Class: FiniteMachine::StateParser Private

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

Overview

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

A class responsible for converting transition arguments to states

Used by TransitionBuilder to parse user input state transitions.

Constant Summary collapse

NON_STATE_KEYS =

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

%i[name if unless silent].freeze
STATE_KEYS =

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

%i[from to].freeze

Class Method Summary collapse

Class Method Details

.parse(attributes, &block) {|Hash[Symbol]| ... } ⇒ Hash[Symbol]

Extract states from user defined attributes

Examples:

StateParser.parse({from: [:green, :blue], to: :red})
# => {green: :red, green: :blue}

Parameters:

  • block (Proc)

Yields:

  • (Hash[Symbol])

    the resolved states

Returns:

  • (Hash[Symbol])

    the resolved states



27
28
29
30
31
# File 'lib/finite_machine/state_parser.rb', line 27

def self.parse(attributes, &block)
  attrs  = ensure_only_states!(attributes)
  states = extract_states(attrs)
  block ? states.each(&block) : states
end