Class: FSM::Transition
- Inherits:
-
Object
- Object
- FSM::Transition
- Includes:
- Options::InstanceMethods
- Defined in:
- lib/fsm/transition.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
Returns the value of attribute event.
-
#from ⇒ Object
Returns the value of attribute from.
-
#guard ⇒ Object
Returns the value of attribute guard.
-
#name ⇒ Object
Returns the value of attribute name.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #fire?(target, args) ⇒ Boolean
- #fire_event(target, args) ⇒ Object
-
#initialize(name, from, to, options = {}) ⇒ Transition
constructor
A new instance of Transition.
- #to_dot(options = {}) ⇒ Object
- #to_s ⇒ Object
Methods included from Options::InstanceMethods
Constructor Details
#initialize(name, from, to, options = {}) ⇒ Transition
Returns a new instance of Transition.
5 6 7 8 9 10 11 12 13 |
# File 'lib/fsm/transition.rb', line 5 def initialize(name, from, to, = {}) raise ArgumentError.new("name, from and to are required but were '#{name}', '#{from}' and '#{to}'") unless name && from && to (, [:event, :guard]) self.name = name self.from = from self.to = to self.event = Executable.new [:event] if .has_key?(:event) self.guard = Executable.new [:guard] if .has_key?(:guard) end |
Instance Attribute Details
#event ⇒ Object
Returns the value of attribute event.
4 5 6 |
# File 'lib/fsm/transition.rb', line 4 def event @event end |
#from ⇒ Object
Returns the value of attribute from.
4 5 6 |
# File 'lib/fsm/transition.rb', line 4 def from @from end |
#guard ⇒ Object
Returns the value of attribute guard.
4 5 6 |
# File 'lib/fsm/transition.rb', line 4 def guard @guard end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/fsm/transition.rb', line 4 def name @name end |
#to ⇒ Object
Returns the value of attribute to.
4 5 6 |
# File 'lib/fsm/transition.rb', line 4 def to @to end |
Instance Method Details
#fire?(target, args) ⇒ Boolean
19 20 21 |
# File 'lib/fsm/transition.rb', line 19 def fire?(target, args) self.guard ? self.guard.execute(target, *args) : true end |
#fire_event(target, args) ⇒ Object
15 16 17 |
# File 'lib/fsm/transition.rb', line 15 def fire_event(target, args) self.event.execute(target, *args) if self.event end |
#to_dot(options = {}) ⇒ Object
27 28 29 |
# File 'lib/fsm/transition.rb', line 27 def to_dot( = {}) "#{self.from.name} -> #{self.to.name} [label=\"#{self.name}\"]" end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/fsm/transition.rb', line 23 def to_s "Transition from #{self.from.name} -> #{self.to.name} with event #{self.event}" end |