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.



4
5
6
# File 'lib/steady_state/attribute/state_machine.rb', line 4

def start
  @start
end

Instance Method Details

#new_state(value, last_valid_value) ⇒ Object



14
15
16
# File 'lib/steady_state/attribute/state_machine.rb', line 14

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

#predicatesObject



22
23
24
# File 'lib/steady_state/attribute/state_machine.rb', line 22

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

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



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

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



18
19
20
# File 'lib/steady_state/attribute/state_machine.rb', line 18

def states
  @states ||= []
end

#transitionsObject



26
27
28
# File 'lib/steady_state/attribute/state_machine.rb', line 26

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