Module: Volt::StateManager
- Included in:
- ArrayModel, Model
- Defined in:
- lib/volt/models/state_manager.rb
Instance Method Summary collapse
-
#change_state_to(state_name, new_state, trigger = true) ⇒ Object
Called from the QueryListener when the data is loaded.
- #state_for(state_name) ⇒ Object
Instance Method Details
#change_state_to(state_name, new_state, trigger = true) ⇒ Object
Called from the QueryListener when the data is loaded
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/volt/models/state_manager.rb', line 13 def change_state_to(state_name, new_state, trigger = true) # use an instance variable for the state storage ivar_name = :"@#{state_name}" old_state = instance_variable_get(ivar_name) instance_variable_set(ivar_name, new_state) # Trigger changed on the 'state' method if old_state != new_state && trigger dep = state_dep_for(state_name, false) dep.changed! if dep end end |
#state_for(state_name) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/volt/models/state_manager.rb', line 3 def state_for(state_name) ivar_name = :"@#{state_name}" # Depend on the dep state_dep_for(state_name).depend instance_variable_get(ivar_name) end |