Module: DatashiftJourney::StateMachines::Extensions

Defined in:
lib/datashift_journey/state_machines/extensions.rb

Instance Method Summary collapse

Instance Method Details

#current_state_indexObject



26
27
28
# File 'lib/datashift_journey/state_machines/extensions.rb', line 26

def current_state_index
  state_paths.to_states.index(state_name).to_i
end

#next_state_nameObject



30
31
32
# File 'lib/datashift_journey/state_machines/extensions.rb', line 30

def next_state_name
  transitions_for.find { |t| t.event == :skip_fwd }.try(:to_name)
end

#pp_state_pathsObject



16
17
18
# File 'lib/datashift_journey/state_machines/extensions.rb', line 16

def pp_state_paths
  state_paths.each_with_index { |s, i| puts "Event [#{s.events[i]}] from=#{s[i].from} to=#{s[i].to}" }
end

#previous_state_nameObject



34
35
36
# File 'lib/datashift_journey/state_machines/extensions.rb', line 34

def previous_state_name
  transitions_for.find { |t| t.event == :back }.try(:to_name)
end

#state_index(state) ⇒ Object

Expects a symbol Returns nil when no such state



22
23
24
# File 'lib/datashift_journey/state_machines/extensions.rb', line 22

def state_index(state)
  state.nil? ? nil : state_paths.to_states.index(state.to_sym).to_i
end

#transitions_forObject



12
13
14
# File 'lib/datashift_journey/state_machines/extensions.rb', line 12

def transitions_for
  self.class.state_machine.events.transitions_for(self)
end