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

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb

Overview

SessionHash is responsible to lazily load the session from store.

Direct Known Subclasses

PersistedSecure::SecureSessionHash

Constant Summary collapse

Unspecified =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole, #sum

Constructor Details

#initialize(store, req) ⇒ SessionHash

Returns a new instance of SessionHash.



62
63
64
65
66
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 62

def initialize(store, req)
  @store = store
  @req = req
  @loaded = false
end

Instance Attribute Details

#idObject



68
69
70
71
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 50

def self.find(req)
  req.get_header RACK_SESSION
end

.set(req, session) ⇒ Object



54
55
56
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 54

def self.set(req, session)
  req.set_header RACK_SESSION, session
end

.set_options(req, options) ⇒ Object



58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 58

def self.set_options(req, options)
  req.set_header RACK_SESSION_OPTIONS, options.dup
end

Instance Method Details

#[](key) ⇒ Object



82
83
84
85
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 108

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

#clearObject



114
115
116
117
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 140

def delete(key)
  load_for_write!
  @data.delete(key.to_s)
end

#destroyObject



119
120
121
122
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 77

def each(&block)
  load_for_read!
  @data.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


163
164
165
166
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 163

def empty?
  load_for_read!
  @data.empty?
end

#exists?Boolean

Returns:

  • (Boolean)


153
154
155
156
157
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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?

Returns:

  • (Boolean)


101
102
103
104
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 101

def has_key?(key)
  load_for_read!
  @data.has_key?(key.to_s)
end

#inspectObject



145
146
147
148
149
150
151
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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

#keysObject



168
169
170
171
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 168

def keys
  load_for_read!
  @data.keys
end

#loaded?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 159

def loaded?
  @loaded
end

#optionsObject



73
74
75
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 73

def options
  @req.session_options
end

#replace(hash) ⇒ Object



135
136
137
138
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 135

def replace(hash)
  load_for_write!
  @data.replace(stringify_keys(hash))
end

#to_hashObject



124
125
126
127
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 129

def update(hash)
  load_for_write!
  @data.update(stringify_keys(hash))
end

#valuesObject



173
174
175
176
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/abstract/id.rb', line 173

def values
  load_for_read!
  @data.values
end