Class: SteadyState::Attribute::State
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SteadyState::Attribute::State
- Defined in:
- lib/steady_state/attribute/state.rb
Instance Attribute Summary collapse
-
#last_valid_value ⇒ Object
Returns the value of attribute last_valid_value.
-
#state_machine ⇒ Object
Returns the value of attribute state_machine.
Instance Method Summary collapse
-
#initialize(state_machine, current_value, last_valid_value) ⇒ State
constructor
A new instance of State.
- #may_become?(new_value) ⇒ Boolean
- #next_values ⇒ Object
- #previous_values ⇒ Object
Constructor Details
#initialize(state_machine, current_value, last_valid_value) ⇒ State
Returns a new instance of State.
6 7 8 9 10 |
# File 'lib/steady_state/attribute/state.rb', line 6 def initialize(state_machine, current_value, last_valid_value) self.state_machine = state_machine self.last_valid_value = last_valid_value super(current_value&.inquiry) end |
Instance Attribute Details
#last_valid_value ⇒ Object
Returns the value of attribute last_valid_value.
4 5 6 |
# File 'lib/steady_state/attribute/state.rb', line 4 def last_valid_value @last_valid_value end |
#state_machine ⇒ Object
Returns the value of attribute state_machine.
4 5 6 |
# File 'lib/steady_state/attribute/state.rb', line 4 def state_machine @state_machine end |
Instance Method Details
#may_become?(new_value) ⇒ Boolean
12 13 14 |
# File 'lib/steady_state/attribute/state.rb', line 12 def may_become?(new_value) next_values.include?(new_value) end |
#next_values ⇒ Object
16 17 18 |
# File 'lib/steady_state/attribute/state.rb', line 16 def next_values @next_values ||= state_machine.transitions[last_valid_value || self] end |
#previous_values ⇒ Object
20 21 22 |
# File 'lib/steady_state/attribute/state.rb', line 20 def previous_values @previous_values ||= state_machine.transitions.select { |_, v| v.include?(last_valid_value || self) }.keys end |