class FiniteMachine::HookEvent
A class responsible for event notification
Constants
- EVENTS
- MESSAGE
Attributes
The event name triggering this hook event
The from state this hook has been fired
HookEvent
state or action name
HookEvent
type
Public Class Methods
Choose any state or event name based on even type
@param [HookEvent] event_type
@return [Symbol]
out of :any or :any_event
@api public
# 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 event hook
@param [Symbol] :state
The state or action name.
@param [Symbol] :event_name
The event name associted with this hook.
@return [self]
@api public
# 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
Extract event name
@return [String] the event name
@api public
# File lib/finite_machine/hook_event.rb, line 31 def self.event_name name.split("::").last.downcase.to_sym end
Instantiate a new HookEvent
object
@param [Symbol] name
The action or state name
@param [Symbol] event_name
The event name associated with this hook event.
@example
HookEvent.new(:green, :move, :green)
@return [self]
@api public
# 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
String representation
@return [String] the event name
@api public
# File lib/finite_machine/hook_event.rb, line 40 def self.to_s event_name.to_s end
Public Instance Methods
Compare whether the instance is greater, less then or equal to other
@return [-1 0 1]
@api public
# 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
Notify subscriber about this event
@param [Observer] subscriber
the object subscribed to be notified about this event
@param [Array] data
the data associated with the triggered event
@return [nil]
@api public
# File lib/finite_machine/hook_event.rb, line 123 def notify(subscriber, *data) return unless subscriber.respond_to?(MESSAGE) subscriber.public_send(MESSAGE, self, *data) end