Class: Ramaze::Session::Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/ramaze/current/session/hash.rb

Overview

The Session::Hash acts as the wrapper for a simple Hash

Its purpose is to notify the underlying cache, in which the sessions are stored, about updates.

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Hash

Sets @hash to an empty Hash



12
13
14
15
# File 'lib/ramaze/current/session/hash.rb', line 12

def initialize(session)
  @session = session
  @hash = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

relays all the methods to the @hash and updates the session_cache in Session.current.sessions if anything changes.



20
21
22
23
24
# File 'lib/ramaze/current/session/hash.rb', line 20

def method_missing(*args, &block)
  result = @hash.send(*args, &block)
  Cache.sessions[@session.session_id] = self
  result
end

Instance Method Details

#clientObject

Use client side session variables



34
35
36
# File 'lib/ramaze/current/session/hash.rb', line 34

def client
  Request.current['session.client'] ||= unmarshal(Request.current.cookies["#{Session::SESSION_KEY}-client"]) || {}
end

#inspectObject

Calls #inspect on the wrapped @hash



28
29
30
# File 'lib/ramaze/current/session/hash.rb', line 28

def inspect
  @hash.inspect
end