class StrictMachine::DefinitionContext
Attributes
states[R]
transitions[R]
Public Class Methods
new()
click to toggle source
# File lib/strict_machine/definition_context.rb, line 7 def initialize @states = [] @transitions = [] end
Public Instance Methods
get_state_by_name(name)
click to toggle source
# File lib/strict_machine/definition_context.rb, line 12 def get_state_by_name(name) @states.each do |this_state| return this_state if this_state.name == name.to_sym end raise StateNotFoundError, name end
initial_state_name()
click to toggle source
# File lib/strict_machine/definition_context.rb, line 20 def initial_state_name @states.first.name end
on(hash)
click to toggle source
# File lib/strict_machine/definition_context.rb, line 39 def on(hash) @states.last.add_transition hash end
on_entry(&block)
click to toggle source
# File lib/strict_machine/definition_context.rb, line 43 def on_entry(&block) @states.last.add_on_entry(block) end
on_transition(&block)
click to toggle source
# File lib/strict_machine/definition_context.rb, line 47 def on_transition(&block) @transitions << block end
run_transitions(instance, current_state, new_state, trigger, duration)
click to toggle source
# File lib/strict_machine/definition_context.rb, line 24 def run_transitions(instance, current_state, new_state, trigger, duration) @transitions.each do |proc| instance.instance_exec( current_state, new_state, trigger, duration, &proc ) end end
state(name, &block)
click to toggle source
DSL
# File lib/strict_machine/definition_context.rb, line 34 def state(name, &block) @states << State.new(name) instance_eval(&block) if block_given? end