Class: FSM::Transition

Inherits:
Object
  • Object
show all
Includes:
Options::InstanceMethods
Defined in:
lib/fsm/transition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Options::InstanceMethods

#assert_options

Constructor Details

#initialize(name, from, to, options = {}) ⇒ Transition

Returns a new instance of Transition.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
# File 'lib/fsm/transition.rb', line 5

def initialize(name, from, to, options = {})
  raise ArgumentError.new("name, from and to are required but were '#{name}', '#{from}' and '#{to}'") unless name && from && to
  assert_options(options, [:event])
  self.name = name
  self.from = from
  self.to = to
  self.event = Executable.new options[:event] if options.has_key?(:event)
end

Instance Attribute Details

#eventObject

Returns the value of attribute event.



4
5
6
# File 'lib/fsm/transition.rb', line 4

def event
  @event
end

#fromObject

Returns the value of attribute from.



4
5
6
# File 'lib/fsm/transition.rb', line 4

def from
  @from
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/fsm/transition.rb', line 4

def name
  @name
end

#toObject

Returns the value of attribute to.



4
5
6
# File 'lib/fsm/transition.rb', line 4

def to
  @to
end

Instance Method Details

#fire_event(target, args) ⇒ Object



14
15
16
# File 'lib/fsm/transition.rb', line 14

def fire_event(target, args)
  self.event.execute(target, *args) if self.event
end

#to_sObject



18
19
20
# File 'lib/fsm/transition.rb', line 18

def to_s
  "Transition from #{self.from.name} -> #{self.to.name} with event #{self.event}"
end