Class: SteadyState::Attribute::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/steady_state/attribute/state_machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#startObject

Returns the value of attribute start.



6
7
8
# File 'lib/steady_state/attribute/state_machine.rb', line 6

def start
  @start
end

Instance Method Details

#new_state(value, last_valid_value) ⇒ Object



16
17
18
# File 'lib/steady_state/attribute/state_machine.rb', line 16

def new_state(value, last_valid_value)
  State.new(self, value, last_valid_value) unless value.nil?
end

#predicatesObject



24
25
26
# File 'lib/steady_state/attribute/state_machine.rb', line 24

def predicates
  states.map { |state| :"#{state.parameterize.underscore}?" }
end

#state(state, default: false, from: []) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/steady_state/attribute/state_machine.rb', line 8

def state(state, default: false, from: [])
  states << state
  self.start = state if default
  [from].flatten(1).each do |from_state|
    transitions[from_state] << state
  end
end

#statesObject



20
21
22
# File 'lib/steady_state/attribute/state_machine.rb', line 20

def states
  @states ||= []
end

#transitionsObject



28
29
30
# File 'lib/steady_state/attribute/state_machine.rb', line 28

def transitions
  @transitions ||= Hash.new { |h, k| h[k] = [] }.with_indifferent_access
end