Class: Rack::Session::Abstract::SessionHash
- Inherits:
-
Object
- Object
- Rack::Session::Abstract::SessionHash
show all
- Includes:
- Enumerable
- Defined in:
- lib/rack/session/abstract/id.rb
Overview
SessionHash is responsible to lazily load the session from store.
Constant Summary
collapse
- Unspecified =
Object.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(store, req) ⇒ SessionHash
Returns a new instance of SessionHash.
68
69
70
71
72
|
# File 'lib/rack/session/abstract/id.rb', line 68
def initialize(store, req)
@store = store
@req = req
@loaded = false
end
|
Instance Attribute Details
#id ⇒ Object
74
75
76
77
|
# File 'lib/rack/session/abstract/id.rb', line 74
def id
return @id if @loaded or instance_variable_defined?(:@id)
@id = @store.send(:extract_session_id, @req)
end
|
Class Method Details
.find(req) ⇒ Object
56
57
58
|
# File 'lib/rack/session/abstract/id.rb', line 56
def self.find(req)
req. RACK_SESSION
end
|
.set(req, session) ⇒ Object
60
61
62
|
# File 'lib/rack/session/abstract/id.rb', line 60
def self.set(req, session)
req. RACK_SESSION, session
end
|
.set_options(req, options) ⇒ Object
64
65
66
|
# File 'lib/rack/session/abstract/id.rb', line 64
def self.set_options(req, options)
req. RACK_SESSION_OPTIONS, options.dup
end
|
Instance Method Details
#[](key) ⇒ Object
88
89
90
91
|
# File 'lib/rack/session/abstract/id.rb', line 88
def [](key)
load_for_read!
@data[key.to_s]
end
|
#[]=(key, value) ⇒ Object
Also known as:
store
114
115
116
117
|
# File 'lib/rack/session/abstract/id.rb', line 114
def []=(key, value)
load_for_write!
@data[key.to_s] = value
end
|
#clear ⇒ Object
120
121
122
123
|
# File 'lib/rack/session/abstract/id.rb', line 120
def clear
load_for_write!
@data.clear
end
|
#delete(key) ⇒ Object
146
147
148
149
|
# File 'lib/rack/session/abstract/id.rb', line 146
def delete(key)
load_for_write!
@data.delete(key.to_s)
end
|
#destroy ⇒ Object
125
126
127
128
|
# File 'lib/rack/session/abstract/id.rb', line 125
def destroy
clear
@id = @store.send(:delete_session, @req, id, options)
end
|
#dig(key, *keys) ⇒ Object
93
94
95
96
|
# File 'lib/rack/session/abstract/id.rb', line 93
def dig(key, *keys)
load_for_read!
@data.dig(key.to_s, *keys)
end
|
#each(&block) ⇒ Object
83
84
85
86
|
# File 'lib/rack/session/abstract/id.rb', line 83
def each(&block)
load_for_read!
@data.each(&block)
end
|
#empty? ⇒ Boolean
169
170
171
172
|
# File 'lib/rack/session/abstract/id.rb', line 169
def empty?
load_for_read!
@data.empty?
end
|
#exists? ⇒ Boolean
159
160
161
162
163
|
# File 'lib/rack/session/abstract/id.rb', line 159
def exists?
return @exists if instance_variable_defined?(:@exists)
@data = {}
@exists = @store.send(:session_exists?, @req)
end
|
#fetch(key, default = Unspecified, &block) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/rack/session/abstract/id.rb', line 98
def fetch(key, default = Unspecified, &block)
load_for_read!
if default == Unspecified
@data.fetch(key.to_s, &block)
else
@data.fetch(key.to_s, default, &block)
end
end
|
#has_key?(key) ⇒ Boolean
Also known as:
key?, include?
107
108
109
110
|
# File 'lib/rack/session/abstract/id.rb', line 107
def has_key?(key)
load_for_read!
@data.has_key?(key.to_s)
end
|
#inspect ⇒ Object
151
152
153
154
155
156
157
|
# File 'lib/rack/session/abstract/id.rb', line 151
def inspect
if loaded?
@data.inspect
else
"#<#{self.class}:0x#{self.object_id.to_s(16)} not yet loaded>"
end
end
|
#keys ⇒ Object
174
175
176
177
|
# File 'lib/rack/session/abstract/id.rb', line 174
def keys
load_for_read!
@data.keys
end
|
#loaded? ⇒ Boolean
165
166
167
|
# File 'lib/rack/session/abstract/id.rb', line 165
def loaded?
@loaded
end
|
#options ⇒ Object
79
80
81
|
# File 'lib/rack/session/abstract/id.rb', line 79
def options
@req.session_options
end
|
#replace(hash) ⇒ Object
141
142
143
144
|
# File 'lib/rack/session/abstract/id.rb', line 141
def replace(hash)
load_for_write!
@data.replace(stringify_keys(hash))
end
|
#to_hash ⇒ Object
130
131
132
133
|
# File 'lib/rack/session/abstract/id.rb', line 130
def to_hash
load_for_read!
@data.dup
end
|
#update(hash) ⇒ Object
Also known as:
merge!
135
136
137
138
|
# File 'lib/rack/session/abstract/id.rb', line 135
def update(hash)
load_for_write!
@data.update(stringify_keys(hash))
end
|
#values ⇒ Object
179
180
181
182
|
# File 'lib/rack/session/abstract/id.rb', line 179
def values
load_for_read!
@data.values
end
|