Class: Brut::TUI::Events::BaseEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/brut/tui/events/base_event.rb

Overview

Base class for all events the TUI will manage. You can create custom events but they must subclass this one (or conform to its interface, which may change).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handler_method_nameObject

Returns the method name that subscribers must implement to handle this event. By default, this is based on the underscorized simple class name (name without module namespacing) suffixed with on_.



9
10
11
12
13
14
# File 'lib/brut/tui/events/base_event.rb', line 9

def self.handler_method_name 
  @handler_method_name ||= begin
                             simple_class_name = RichString.new(self.name.split("::").last)
                             "on_#{simple_class_name.underscorized}"
                           end
end

Instance Method Details

#deconstruct_keys(keys = nil) ⇒ Object

Provides class_name and handler_method_name. Subclasses are expected to call this so they are included with their keys.



18
19
20
# File 'lib/brut/tui/events/base_event.rb', line 18

def deconstruct_keys(keys=nil)
  { class_name: self.class.name, handler_method_name: self.class.handler_method_name }
end

#drain_then_exit?Boolean

True if this event indicates the TUI should exit, but draining any outstanding events is OK first.

Returns:

  • (Boolean)


28
# File 'lib/brut/tui/events/base_event.rb', line 28

def drain_then_exit? = false

#exit?Boolean

True if the reception of this event indicates the app should exit right now, potentially leaving un-handled events.

Returns:

  • (Boolean)


24
# File 'lib/brut/tui/events/base_event.rb', line 24

def exit? = false