Class: Statesman::EventTransitions

Inherits:
Object
  • Object
show all
Defined in:
lib/statesman/event_transitions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, event_name, &block) ⇒ EventTransitions



5
6
7
8
9
# File 'lib/statesman/event_transitions.rb', line 5

def initialize(machine, event_name, &block)
  @machine    = machine
  @event_name = event_name
  instance_eval(&block)
end

Instance Attribute Details

#event_nameObject (readonly)

Returns the value of attribute event_name.



3
4
5
# File 'lib/statesman/event_transitions.rb', line 3

def event_name
  @event_name
end

#machineObject (readonly)

Returns the value of attribute machine.



3
4
5
# File 'lib/statesman/event_transitions.rb', line 3

def machine
  @machine
end

Instance Method Details

#transition(from: nil, to: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/statesman/event_transitions.rb', line 11

def transition(from: nil, to: nil)
  from = to_s_or_nil(from)
  to = array_to_s_or_nil(to)

  machine.transition(from: from, to: to)

  machine.events[event_name] ||= {}
  machine.events[event_name][from] ||= []
  machine.events[event_name][from] += to
end