Class: AnyCable::Rails::Connections::SessionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/anycable/rails/connections/session_proxy.rb

Overview

Wrap request.session to lazily load values provided in the RPC call (set by the previous calls)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rack_session, socket_session) ⇒ SessionProxy

Returns a new instance of SessionProxy.



11
12
13
14
# File 'lib/anycable/rails/connections/session_proxy.rb', line 11

def initialize(rack_session, socket_session)
  @rack_session = rack_session
  @socket_session = JSON.parse(socket_session).with_indifferent_access
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/anycable/rails/connections/session_proxy.rb', line 49

def method_missing(method, ...)
  if rack_session.respond_to?(method, true)
    rack_session.send(method, ...)
  else
    super
  end
end

Instance Attribute Details

#rack_sessionObject (readonly)

Returns the value of attribute rack_session.



9
10
11
# File 'lib/anycable/rails/connections/session_proxy.rb', line 9

def rack_session
  @rack_session
end

#socket_sessionObject (readonly)

Returns the value of attribute socket_session.



9
10
11
# File 'lib/anycable/rails/connections/session_proxy.rb', line 9

def socket_session
  @socket_session
end

Instance Method Details

#instance_variable_get(name) ⇒ Object

This method is used by StimulusReflex to obtain ‘@by`



58
59
60
# File 'lib/anycable/rails/connections/session_proxy.rb', line 58

def instance_variable_get(name)
  super || rack_session.instance_variable_get(name)
end

#keysObject



39
40
41
# File 'lib/anycable/rails/connections/session_proxy.rb', line 39

def keys
  rack_session.keys + socket_session.keys
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Delegate both publuc and private methods to rack_session

Returns:



44
45
46
47
# File 'lib/anycable/rails/connections/session_proxy.rb', line 44

def respond_to_missing?(name, include_private = false)
  return false if name == :marshal_dump || name == :_dump
  rack_session.respond_to?(name, include_private) || super
end