Class: Netzke::Core::Session::ComponentSessionProxy

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

Overview

Instance of this class is returned through component_session, and allows writing/reading to/from the session part reserved for a specific component (specified by component's js_id).

Instance Method Summary collapse

Constructor Details

#initialize(component_id) ⇒ ComponentSessionProxy



6
7
8
9
10
# File 'lib/netzke/core/session.rb', line 6

def initialize(component_id)
  @component_id = component_id.to_s
  Netzke::Base.session ||= {}
  Netzke::Base.session[:netzke_sessions] ||= {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Delegate everything to session



13
14
15
16
17
18
# File 'lib/netzke/core/session.rb', line 13

def method_missing(method, *args)
  session_data = to_hash
  session_data.send(method, *args).tap do |d|
    Netzke::Base.session[:netzke_sessions] = {@component_id => session_data}
  end
end

Instance Method Details

#clearObject



20
21
22
# File 'lib/netzke/core/session.rb', line 20

def clear
  Netzke::Base.session[:netzke_sessions].delete(@component_id)
end

#to_hashObject



24
25
26
# File 'lib/netzke/core/session.rb', line 24

def to_hash
  ActiveSupport::HashWithIndifferentAccess.new(Netzke::Base.session[:netzke_sessions][@component_id] || {})
end