class FiniteMachine::TransitionBuilder
A class reponsible for building transition out of parsed states
Used internally by {DSL} to
@api private
Public Class Methods
new(machine, name, attributes = {})
click to toggle source
Initialize a TransitionBuilder
@example
TransitionBuilder.new(machine, {})
@api public
# File lib/finite_machine/transition_builder.rb, line 21 def initialize(machine, name, attributes = {}) @machine = machine @name = name @attributes = attributes @event_definition = EventDefinition.new(machine) @state_definition = StateDefinition.new(machine) end
Public Instance Methods
call(transitions)
click to toggle source
Converts user transitions into internal {Transition} representation
@example
transition_builder.call([:green, :yellow] => :red)
@param [Hash] transitions
The transitions to extract states from
@return [self]
@api public
# File lib/finite_machine/transition_builder.rb, line 41 def call(transitions) StateParser.parse(transitions) do |from, to| transition = Transition.new(@machine.env.target, @name, @attributes.merge(states: { from => to })) silent = @attributes.fetch(:silent, false) @machine.events_map.add(@name, transition) next unless @machine.auto_methods? unless @machine.respond_to?(@name) @event_definition.apply(@name, silent) end @state_definition.apply(from => to) end self end