Sha256: ea18cb98dee847f719b1f45b5837b8b6eaaced388db5279289a0ce47cb1f4fa1

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

module FiniteMachine
  # A class reponsible for building transition out of parsed states
  #
  # @api private
  class TransitionBuilder
    include Threadable

    # The current state machine
    attr_threadsafe :machine

    attr_threadsafe :attributes

    attr_threadsafe :event_definition

    # Initialize a TransitionBuilder
    #
    # @example
    #   TransitionBuilder.new(machine, {})
    #
    # @api public
    def initialize(machine, attributes = {})
      @machine = machine
      @attributes = attributes
      @event_definition = EventDefinition.new(machine)
    end

    # Creates transitions for the states
    #
    # @example
    #   transition_parser.call([:green, :yellow] => :red)
    #
    # @param [Hash[Symbol]] states
    #   The states to extract
    #
    # @return [nil]
    #
    # @api public
    def call(states)
      FiniteMachine::StateParser.new(states).parse do |from, to|
        attributes.merge!(parsed_states: { from => to })
        transition = Transition.create(machine, attributes)
        event_definition.apply(transition)
      end
    end
  end # TransitionBuilder
end # FiniteMachine

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
finite_machine-0.10.2 lib/finite_machine/transition_builder.rb