Class: Netzke::Core::State::StateProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/netzke/core/state.rb

Instance Method Summary collapse

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

#clearObject



36
37
38
# File 'lib/netzke/core/state.rb', line 36

def clear
  state_session.delete(@key)
end

#to_hashObject



32
33
34
# File 'lib/netzke/core/state.rb', line 32

def to_hash
  ActiveSupport::HashWithIndifferentAccess.new(state_session[@key] || {})
end