Class: Stealth::Flow::Event
- Inherits:
-
Object
- Object
- Stealth::Flow::Event
- Defined in:
- lib/stealth/flow/event.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#name ⇒ Object
Returns the value of attribute name.
-
#transitions_to ⇒ Object
Returns the value of attribute transitions_to.
Instance Method Summary collapse
- #condition_applicable?(object) ⇒ Boolean
- #draw(graph, from_state) ⇒ Object
-
#initialize(name, transitions_to, condition = nil, meta = {}, &action) ⇒ Event
constructor
A new instance of Event.
- #to_s ⇒ Object
Constructor Details
#initialize(name, transitions_to, condition = nil, meta = {}, &action) ⇒ Event
Returns a new instance of Event.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/stealth/flow/event.rb', line 10 def initialize(name, transitions_to, condition = nil, = {}, &action) @name = name @transitions_to = transitions_to.to_sym @meta = @action = action @condition = if condition.nil? || condition.is_a?(Symbol) || condition.respond_to?(:call) condition else raise TypeError, 'condition must be nil, an instance method name symbol or a callable (eg. a proc or lambda)' end end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
8 9 10 |
# File 'lib/stealth/flow/event.rb', line 8 def action @action end |
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/stealth/flow/event.rb', line 8 def condition @condition end |
#meta ⇒ Object
Returns the value of attribute meta.
8 9 10 |
# File 'lib/stealth/flow/event.rb', line 8 def @meta end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/stealth/flow/event.rb', line 8 def name @name end |
#transitions_to ⇒ Object
Returns the value of attribute transitions_to.
8 9 10 |
# File 'lib/stealth/flow/event.rb', line 8 def transitions_to @transitions_to end |
Instance Method Details
#condition_applicable?(object) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stealth/flow/event.rb', line 22 def condition_applicable?(object) if condition if condition.is_a?(Symbol) object.send(condition) else condition.call(object) end else true end end |
#draw(graph, from_state) ⇒ Object
34 35 36 |
# File 'lib/stealth/flow/event.rb', line 34 def draw(graph, from_state) graph.add_edges(from_state.name.to_s, transitions_to.to_s, .merge(:label => to_s)) end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/stealth/flow/event.rb', line 38 def to_s @name.to_s end |