Class: Rack::Session::Abstract::SessionHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/rack/session/abstract/id.rb

Overview

SessionHash is responsible to lazily load the session from store.

Instance Method Summary collapse

Constructor Details

#initialize(by, env) ⇒ SessionHash

Returns a new instance of SessionHash.



51
52
53
54
55
56
# File 'lib/rack/session/abstract/id.rb', line 51

def initialize(by, env)
  super()
  @by = by
  @env = env
  @loaded = false
end

Instance Method Details

#[](key) ⇒ Object



58
59
60
61
# File 'lib/rack/session/abstract/id.rb', line 58

def [](key)
  load_for_read!
  super(key.to_s)
end

#[]=(key, value) ⇒ Object



70
71
72
73
# File 'lib/rack/session/abstract/id.rb', line 70

def []=(key, value)
  load_for_write!
  super(key.to_s, value)
end

#clearObject



75
76
77
78
# File 'lib/rack/session/abstract/id.rb', line 75

def clear
  load_for_write!
  super
end

#delete(key) ⇒ Object



92
93
94
95
# File 'lib/rack/session/abstract/id.rb', line 92

def delete(key)
  load_for_write!
  super(key.to_s)
end

#exists?Boolean

Returns:

  • (Boolean)


102
103
104
105
# File 'lib/rack/session/abstract/id.rb', line 102

def exists?
  return @exists if instance_variable_defined?(:@exists)
  @exists = @by.send(:session_exists?, @env)
end

#has_key?(key) ⇒ Boolean Also known as: key?, include?

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/rack/session/abstract/id.rb', line 63

def has_key?(key)
  load_for_read!
  super(key.to_s)
end

#inspectObject



97
98
99
100
# File 'lib/rack/session/abstract/id.rb', line 97

def inspect
  load_for_read!
  super
end

#loaded?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/rack/session/abstract/id.rb', line 107

def loaded?
  @loaded
end

#to_hashObject



80
81
82
83
84
85
# File 'lib/rack/session/abstract/id.rb', line 80

def to_hash
  load_for_read!
  h = {}.replace(self)
  h.delete_if { |k,v| v.nil? }
  h
end

#update(hash) ⇒ Object



87
88
89
90
# File 'lib/rack/session/abstract/id.rb', line 87

def update(hash)
  load_for_write!
  super(stringify_keys(hash))
end