Class: Culpa::SessionDrivers::InMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/culpa/session_drivers/in_memory.rb

Constant Summary collapse

@@persist =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, session_id) ⇒ InMemory

Returns a new instance of InMemory.



11
12
13
14
15
# File 'lib/culpa/session_drivers/in_memory.rb', line 11

def initialize(options, session_id)
  @options = options
  @session_id = session_id || SecureRandom.hex
  generate_session_struct unless session_exists?
end

Instance Attribute Details

#session_idObject (readonly)

Returns the value of attribute session_id.



7
8
9
# File 'lib/culpa/session_drivers/in_memory.rb', line 7

def session_id
  @session_id
end

Instance Method Details

#[](k) ⇒ Object



21
22
23
24
25
# File 'lib/culpa/session_drivers/in_memory.rb', line 21

def [](k)
  return nil unless is_valid?
  session_prologation
  @@persist[@session_id][:data][k]
end

#[]=(k, v) ⇒ Object



27
28
29
30
# File 'lib/culpa/session_drivers/in_memory.rb', line 27

def []=(k,v)
  session_prologation
  @@persist[@session_id][:data][k] = v
end

#clear!Object



17
18
19
# File 'lib/culpa/session_drivers/in_memory.rb', line 17

def clear!
  @@persist.delete(@session_id)
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/culpa/session_drivers/in_memory.rb', line 32

def has_key?(key)
  return false unless is_valid?
  @@persist[@session_id][:data].has_key? key
end

#merge!(new_hash) ⇒ Object



37
38
39
# File 'lib/culpa/session_drivers/in_memory.rb', line 37

def merge!(new_hash)
  @@persist[@session_id][:data].merge!(new_hash)
end