Class: Workflow::Event
- Inherits:
-
Object
- Object
- Workflow::Event
- Defined in:
- lib/workflow/event.rb
Defined Under Namespace
Classes: Conditions, Transition
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
- #evaluate(target) ⇒ Object
-
#initialize(name, meta) ⇒ Event
constructor
A new instance of Event.
- #inspect ⇒ Object
- #to(target_state, **conditions_def, &block) ⇒ Object
Constructor Details
#initialize(name, meta) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 |
# File 'lib/workflow/event.rb', line 5 def initialize(name, ) @name = name.to_sym @transitions = [] = || {} end |
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
3 4 5 |
# File 'lib/workflow/event.rb', line 3 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/workflow/event.rb', line 3 def name @name end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
3 4 5 |
# File 'lib/workflow/event.rb', line 3 def transitions @transitions end |
Instance Method Details
#evaluate(target) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/workflow/event.rb', line 15 def evaluate(target) transition = transitions.find{|t| t.apply? target} if transition return transition.target_state else nil end end |
#inspect ⇒ Object
11 12 13 |
# File 'lib/workflow/event.rb', line 11 def inspect "<Event name=#{name.inspect} transitions(#{transitions.length})=#{transitions.inspect}>" end |
#to(target_state, **conditions_def, &block) ⇒ Object
24 25 26 27 |
# File 'lib/workflow/event.rb', line 24 def to(target_state, **conditions_def, &block) conditions = Conditions.new &&conditions_def, block self.transitions << Transition.new(target_state, conditions_def, &block) end |