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.
62
63
64
65
66
|
# File 'lib/rack/session/abstract/id.rb', line 62
def initialize(store, req)
@store = store
@req = req
@loaded = false
end
|
Instance Attribute Details
#id ⇒ Object
68
69
70
71
|
# File 'lib/rack/session/abstract/id.rb', line 68
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
50
51
52
|
# File 'lib/rack/session/abstract/id.rb', line 50
def self.find(req)
req. RACK_SESSION
end
|
.set(req, session) ⇒ Object
54
55
56
|
# File 'lib/rack/session/abstract/id.rb', line 54
def self.set(req, session)
req. RACK_SESSION, session
end
|
.set_options(req, options) ⇒ Object
58
59
60
|
# File 'lib/rack/session/abstract/id.rb', line 58
def self.set_options(req, options)
req. RACK_SESSION_OPTIONS, options.dup
end
|
Instance Method Details
#[](key) ⇒ Object
82
83
84
85
|
# File 'lib/rack/session/abstract/id.rb', line 82
def [](key)
load_for_read!
@data[key.to_s]
end
|
#[]=(key, value) ⇒ Object
Also known as:
store
108
109
110
111
|
# File 'lib/rack/session/abstract/id.rb', line 108
def []=(key, value)
load_for_write!
@data[key.to_s] = value
end
|
#clear ⇒ Object
114
115
116
117
|
# File 'lib/rack/session/abstract/id.rb', line 114
def clear
load_for_write!
@data.clear
end
|
#delete(key) ⇒ Object
140
141
142
143
|
# File 'lib/rack/session/abstract/id.rb', line 140
def delete(key)
load_for_write!
@data.delete(key.to_s)
end
|
#destroy ⇒ Object
119
120
121
122
|
# File 'lib/rack/session/abstract/id.rb', line 119
def destroy
clear
@id = @store.send(:delete_session, @req, id, options)
end
|
#dig(key, *keys) ⇒ Object
87
88
89
90
|
# File 'lib/rack/session/abstract/id.rb', line 87
def dig(key, *keys)
load_for_read!
@data.dig(key.to_s, *keys)
end
|
#each(&block) ⇒ Object
77
78
79
80
|
# File 'lib/rack/session/abstract/id.rb', line 77
def each(&block)
load_for_read!
@data.each(&block)
end
|
#empty? ⇒ Boolean
163
164
165
166
|
# File 'lib/rack/session/abstract/id.rb', line 163
def empty?
load_for_read!
@data.empty?
end
|
#exists? ⇒ Boolean
153
154
155
156
157
|
# File 'lib/rack/session/abstract/id.rb', line 153
def exists?
return @exists if instance_variable_defined?(:@exists)
@data = {}
@exists = @store.send(:session_exists?, @req)
end
|
#fetch(key, default = Unspecified, &block) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/rack/session/abstract/id.rb', line 92
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?
101
102
103
104
|
# File 'lib/rack/session/abstract/id.rb', line 101
def has_key?(key)
load_for_read!
@data.has_key?(key.to_s)
end
|
#inspect ⇒ Object
145
146
147
148
149
150
151
|
# File 'lib/rack/session/abstract/id.rb', line 145
def inspect
if loaded?
@data.inspect
else
"#<#{self.class}:0x#{self.object_id.to_s(16)} not yet loaded>"
end
end
|
#keys ⇒ Object
168
169
170
171
|
# File 'lib/rack/session/abstract/id.rb', line 168
def keys
load_for_read!
@data.keys
end
|
#loaded? ⇒ Boolean
159
160
161
|
# File 'lib/rack/session/abstract/id.rb', line 159
def loaded?
@loaded
end
|
#options ⇒ Object
73
74
75
|
# File 'lib/rack/session/abstract/id.rb', line 73
def options
@req.session_options
end
|
#replace(hash) ⇒ Object
135
136
137
138
|
# File 'lib/rack/session/abstract/id.rb', line 135
def replace(hash)
load_for_write!
@data.replace(stringify_keys(hash))
end
|
#to_hash ⇒ Object
124
125
126
127
|
# File 'lib/rack/session/abstract/id.rb', line 124
def to_hash
load_for_read!
@data.dup
end
|
#update(hash) ⇒ Object
Also known as:
merge!
129
130
131
132
|
# File 'lib/rack/session/abstract/id.rb', line 129
def update(hash)
load_for_write!
@data.update(stringify_keys(hash))
end
|
#values ⇒ Object
173
174
175
176
|
# File 'lib/rack/session/abstract/id.rb', line 173
def values
load_for_read!
@data.values
end
|