Class: Statum::Event
- Inherits:
-
Object
- Object
- Statum::Event
- Defined in:
- lib/statum/event.rb
Overview
Class for storing event info
Instance Attribute Summary collapse
-
#after ⇒ Statum::Hook
After hook object.
-
#before ⇒ Statum::Hook
Before hook object.
-
#from ⇒ Symbol, Array
From state name (or names).
-
#to ⇒ Symbol
To state name.
Instance Method Summary collapse
-
#can_fire?(current_state) ⇒ Boolean
Returns true if event can be fired from current state.
-
#initialize(from, to, options = {}) ⇒ Event
constructor
Creates an event class.
Constructor Details
#initialize(from, to, options = {}) ⇒ Event
Creates an event class
16 17 18 19 20 21 |
# File 'lib/statum/event.rb', line 16 def initialize(from, to, = {}) @from = from.is_a?(Array) ? from.map(&:to_sym) : from.to_sym @to = to.to_sym @before = Statum::Hook.new(.fetch(:before, nil)) @after = Statum::Hook.new(.fetch(:after, nil)) end |
Instance Attribute Details
#after ⇒ Statum::Hook
After hook object
8 9 10 |
# File 'lib/statum/event.rb', line 8 def after @after end |
#before ⇒ Statum::Hook
Before hook object
8 9 10 |
# File 'lib/statum/event.rb', line 8 def before @before end |
#from ⇒ Symbol, Array
From state name (or names)
8 9 10 |
# File 'lib/statum/event.rb', line 8 def from @from end |
#to ⇒ Symbol
To state name
8 9 10 |
# File 'lib/statum/event.rb', line 8 def to @to end |
Instance Method Details
#can_fire?(current_state) ⇒ Boolean
Returns true if event can be fired from current state
28 29 30 31 32 33 34 35 36 |
# File 'lib/statum/event.rb', line 28 def can_fire?(current_state) if from.is_a?(Array) from.include?(current_state.to_sym) elsif from == Statum::ANY_STATE_NAME true else from == current_state.to_sym end end |