Module: Hecks::Bluebook::Behaviour::Lifecycle

Included in:
Lifecycle
Defined in:
lib/hecks/bluebook/behaviour/lifecycle.rb

Overview

WHAT A LIFECYCLE DOES. Its declared half is a field, a starting state and a transition list. Everything here READS that — which states exist, which transition a command takes, and how one declared transition expands into the several rows the emission carries when from names more than one source state.

Instance Method Summary collapse

Instance Method Details

#statesObject



10
11
12
# File 'lib/hecks/bluebook/behaviour/lifecycle.rb', line 10

def states
  ([default] + transitions.map { |_command, t| t.target }).uniq
end

#target_for(command, current_state = nil) ⇒ Object



18
19
20
# File 'lib/hecks/bluebook/behaviour/lifecycle.rb', line 18

def target_for(command, current_state = nil)
  match_transition(command, current_state)&.target
end

#transitions_for(command) ⇒ Object



14
15
16
# File 'lib/hecks/bluebook/behaviour/lifecycle.rb', line 14

def transitions_for(command)
  transitions.select { |name, _| name == command.to_s }.map { |_, t| t }
end