Sha256: b466c6b27d593f44408c30e36d3cba7f2bb12971d630ee625ee2ad585d5af620

Contents?: true

Size: 1001 Bytes

Versions: 3

Compression:

Stored size: 1001 Bytes

Contents

# encoding: utf-8

module FiniteMachine
  # A class responsible for merging choice options
  class ChoiceMerger
    include Threadable

    # The context where choice is executed
    attr_threadsafe :context

    # The options passed in to the context
    attr_threadsafe :options

    # Initialize a ChoiceMerger
    #
    # @api private
    def initialize(context, options)
      self.context = context
      self.options = options
    end

    # Create choice transition
    #
    # @example
    #   event from: :green do
    #     choice :yellow
    #   end
    #
    # @param [Symbol] to
    #   the to state
    # @param [Hash] attrs
    #
    # @return [FiniteMachine::Transition]
    #
    # @api public
    def choice(to, attrs = {})
      opts = options.dup
      opts.merge!(attrs)
      transition_builder = TransitionBuilder.new(context.machine, opts)
      transition_builder.call(options[:from] => to)
    end
    alias_method :default, :choice
  end # ChoiceMerger
end # FiniteMachine

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
finite_machine-0.10.0 lib/finite_machine/choice_merger.rb
finite_machine-0.9.2 lib/finite_machine/choice_merger.rb
finite_machine-0.9.1 lib/finite_machine/choice_merger.rb