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.
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 |
#predicates ⇒ Object
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 |
#states ⇒ Object
18 19 20 |
# File 'lib/steady_state/attribute/state_machine.rb', line 18 def states @states ||= [] end |
#transitions ⇒ Object
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 |