Class: FiniteMachine::ChoiceMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/finite_machine/choice_merger.rb

Overview

A class responsible for merging choice options

Instance Method Summary collapse

Constructor Details

#initialize(machine, name, transitions = {}) ⇒ ChoiceMerger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a ChoiceMerger

Parameters:

  • machine (StateMachine)
  • name (String)
  • transitions (Hash) (defaults to: {})

    the transitions and attributes



16
17
18
19
20
# File 'lib/finite_machine/choice_merger.rb', line 16

def initialize(machine, name, transitions = {})
  @machine     = machine
  @name        = name
  @transitions = transitions
end

Instance Method Details

#choice(to, conditions = {}) ⇒ FiniteMachine::Transition Also known as: default

Create choice transition

Examples:

event :stop, from: :green do
  choice :yellow
end

Parameters:

  • to (Symbol)

    the to state

  • conditions (Hash) (defaults to: {})

    the conditions associated with this choice

Returns:



37
38
39
40
41
# File 'lib/finite_machine/choice_merger.rb', line 37

def choice(to, conditions = {})
  transition_builder = TransitionBuilder.new(@machine, @name,
                                             @transitions.merge(conditions))
  transition_builder.call(@transitions[:from] => to)
end