Class: FiniteMachine::HookEvent
- Inherits:
-
Object
- Object
- FiniteMachine::HookEvent
- Includes:
- Comparable
- Defined in:
- lib/finite_machine/hook_event.rb
Overview
A class responsible for event notification
Defined Under Namespace
Classes: After, Anyaction, Anystate, Before, Enter, Exit, Transition
Constant Summary collapse
- EVENTS =
Anystate, Enter, Transition, Exit, Anyaction, Before, After
- MESSAGE =
:emit
Instance Attribute Summary collapse
-
#event_name ⇒ Object
readonly
The event name triggering this hook event.
-
#from ⇒ Object
readonly
The from state this hook has been fired.
-
#name ⇒ Object
readonly
HookEvent state or action name.
-
#type ⇒ Object
readonly
HookEvent type.
Class Method Summary collapse
-
.any_state_or_event(event_type) ⇒ Symbol
Choose any state or event name based on even type.
-
.build(state, event_name, from) ⇒ self
Build event hook.
-
.event_name ⇒ String
Extract event name.
-
.to_s ⇒ String
String representation.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1 0 1
Compare whether the instance is greater, less then or equal to other.
-
#initialize(name, event_name, from) ⇒ self
constructor
Instantiate a new HookEvent object.
-
#notify(subscriber, *data) ⇒ nil
Notify subscriber about this event.
Constructor Details
#initialize(name, event_name, from) ⇒ self
Instantiate a new HookEvent object
104 105 106 107 108 109 110 |
# File 'lib/finite_machine/hook_event.rb', line 104 def initialize(name, event_name, from) @name = name @type = self.class @event_name = event_name @from = from freeze end |
Instance Attribute Details
#event_name ⇒ Object (readonly)
The event name triggering this hook event
88 89 90 |
# File 'lib/finite_machine/hook_event.rb', line 88 def event_name @event_name end |
#from ⇒ Object (readonly)
The from state this hook has been fired
85 86 87 |
# File 'lib/finite_machine/hook_event.rb', line 85 def from @from end |
#name ⇒ Object (readonly)
HookEvent state or action name
79 80 81 |
# File 'lib/finite_machine/hook_event.rb', line 79 def name @name end |
#type ⇒ Object (readonly)
HookEvent type
82 83 84 |
# File 'lib/finite_machine/hook_event.rb', line 82 def type @type end |
Class Method Details
.any_state_or_event(event_type) ⇒ Symbol
Choose any state or event name based on even type
52 53 54 |
# File 'lib/finite_machine/hook_event.rb', line 52 def self.any_state_or_event(event_type) event_type < Anyaction ? ANY_EVENT : ANY_STATE end |
.build(state, event_name, from) ⇒ self
Build event hook
67 68 69 70 |
# File 'lib/finite_machine/hook_event.rb', line 67 def self.build(state, event_name, from) state_or_action = self < Anystate ? state : event_name new(state_or_action, event_name, from) end |
.event_name ⇒ String
Extract event name
31 32 33 |
# File 'lib/finite_machine/hook_event.rb', line 31 def self.event_name name.split("::").last.downcase.to_sym end |
.to_s ⇒ String
String representation
40 41 42 |
# File 'lib/finite_machine/hook_event.rb', line 40 def self.to_s event_name.to_s end |
Instance Method Details
#<=>(other) ⇒ -1 0 1
Compare whether the instance is greater, less then or equal to other
134 135 136 137 |
# File 'lib/finite_machine/hook_event.rb', line 134 def <=>(other) other.is_a?(type) && [name, from, event_name] <=> [other.name, other.from, other.event_name] end |