Class: StateMachineChecker::Adapters::StateMachines

Inherits:
Object
  • Object
show all
Defined in:
lib/state_machine_checker/adapters/state_machines.rb

Overview

An adapter for the state_machines gem.

Instance Method Summary collapse

Constructor Details

#initialize(gem_machine) ⇒ StateMachines

Returns a new instance of StateMachines.

Parameters:

  • gem_machine (StateMachines::Machine)

8
9
10
# File 'lib/state_machine_checker/adapters/state_machines.rb', line 8

def initialize(gem_machine)
  @gem_machine = gem_machine
end

Instance Method Details

#initial_stateObject


12
13
14
15
16
17
18
# File 'lib/state_machine_checker/adapters/state_machines.rb', line 12

def initial_state  # StateMachines::Machine#initial_state takes an instance as a parameter,
  # even when the initial state is set statically. We are assuming that
  # it is always set statically.
  # TODO: could get this by `gem_machine.states.find(&:initial)`

  gem_machine.instance_variable_get(:@initial_state)
end

#transitionsObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/state_machine_checker/adapters/state_machines.rb', line 20

def transitions
  gem_machine.events.flat_map { |event|
    event.branches.flat_map { |branch|
      branch.state_requirements.flat_map { |state_requirement|
        froms = state_requirement[:from].values
        tos = state_requirement[:to].values

        froms.product(tos).map { |from, to|
          Transition.new(from, to, event.name)
        }
      }
    }
  }
end