Class: SteadyState::Attribute::StateMachine
- Inherits:
-
Object
- Object
- SteadyState::Attribute::StateMachine
- Defined in:
- lib/steady_state/attribute/state_machine.rb
Instance Attribute Summary collapse
-
#start ⇒ Object
Returns the value of attribute start.
Instance Method Summary collapse
- #new_state(value, last_valid_value) ⇒ Object
- #predicates ⇒ Object
- #state(state, default: false, from: []) ⇒ Object
- #states ⇒ Object
- #transitions ⇒ Object
Instance Attribute Details
#start ⇒ Object
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 |
#predicates ⇒ Object
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 |
#states ⇒ Object
20 21 22 |
# File 'lib/steady_state/attribute/state_machine.rb', line 20 def states @states ||= [] end |
#transitions ⇒ Object
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 |