Class: Netzke::Core::State::StateProxy
- Inherits:
-
Object
- Object
- Netzke::Core::State::StateProxy
- Defined in:
- lib/netzke/core/state.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(key) ⇒ StateProxy
constructor
A new instance of StateProxy.
-
#method_missing(method, *args) ⇒ Object
Delegate everything to session.
- #to_hash ⇒ Object
Constructor Details
#initialize(key) ⇒ StateProxy
Returns a new instance of StateProxy.
18 19 20 21 22 |
# File 'lib/netzke/core/state.rb', line 18 def initialize(key) @key = key.to_s Netzke::Base.session ||= {} Netzke::Base.session[:netzke_states] ||= {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Delegate everything to session
25 26 27 28 29 30 |
# File 'lib/netzke/core/state.rb', line 25 def method_missing(method, *args) session_data = to_hash session_data.send(method, *args).tap do |d| Netzke::Base.session[:netzke_states] = state_session.merge(@key => session_data) end end |
Instance Method Details
#clear ⇒ Object
36 37 38 |
# File 'lib/netzke/core/state.rb', line 36 def clear state_session.delete(@key) end |
#to_hash ⇒ Object
32 33 34 |
# File 'lib/netzke/core/state.rb', line 32 def to_hash ActiveSupport::HashWithIndifferentAccess.new(state_session[@key] || {}) end |