Class: ActionDispatch::Request::Session
- Defined in:
- actionpack/lib/action_dispatch/request/session.rb
Overview
Session is responsible for lazily loading the session from store.
Defined Under Namespace
Classes: Options
Constant Summary collapse
- ENV_SESSION_KEY =
:nodoc:
Rack::Session::Abstract::ENV_SESSION_KEY
- ENV_SESSION_OPTIONS_KEY =
:nodoc:
Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
- Unspecified =
Singleton object used to determine if an optional param wasn’t specified
Object.new
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #destroy ⇒ Object
- #empty? ⇒ Boolean
- #exists? ⇒ Boolean
- #fetch(key, default = Unspecified, &block) ⇒ Object
- #has_key?(key) ⇒ Boolean (also: #key?, #include?)
- #id ⇒ Object
-
#initialize(by, env) ⇒ Session
constructor
A new instance of Session.
- #inspect ⇒ Object
- #keys ⇒ Object
- #loaded? ⇒ Boolean
- #merge!(other) ⇒ Object
- #options ⇒ Object
- #to_hash ⇒ Object
- #update(hash) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(by, env) ⇒ Session
Returns a new instance of Session.
61 62 63 64 65 66 67 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 61 def initialize(by, env) @by = by @env = env @delegate = {} @loaded = false @exists = nil # we haven't checked yet end |
Class Method Details
.create(store, env, default_options) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 13 def self.create(store, env, ) session_was = find env session = Request::Session.new(store, env) session.merge! session_was if session_was set(env, session) Options.set(env, Request::Session::Options.new(store, env, )) session end |
.find(env) ⇒ Object
23 24 25 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 23 def self.find(env) env[ENV_SESSION_KEY] end |
.set(env, session) ⇒ Object
27 28 29 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 27 def self.set(env, session) env[ENV_SESSION_KEY] = session end |
Instance Method Details
#[](key) ⇒ Object
88 89 90 91 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 88 def [](key) load_for_read! @delegate[key.to_s] end |
#[]=(key, value) ⇒ Object
108 109 110 111 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 108 def []=(key, value) load_for_write! @delegate[key.to_s] = value end |
#clear ⇒ Object
113 114 115 116 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 113 def clear load_for_write! @delegate.clear end |
#delete(key) ⇒ Object
128 129 130 131 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 128 def delete(key) load_for_write! @delegate.delete key.to_s end |
#destroy ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 77 def destroy clear = self. || {} new_sid = @by.send(:destroy_session, @env, [:id], ) [:id] = new_sid # Reset session id with a new value or nil # Load the new sid to be written with the response @loaded = false load_for_write! end |
#empty? ⇒ Boolean
159 160 161 162 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 159 def empty? load_for_read! @delegate.empty? end |
#exists? ⇒ Boolean
150 151 152 153 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 150 def exists? return @exists unless @exists.nil? @exists = @by.send(:session_exists?, @env) end |
#fetch(key, default = Unspecified, &block) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 133 def fetch(key, default=Unspecified, &block) load_for_read! if default == Unspecified @delegate.fetch(key.to_s, &block) else @delegate.fetch(key.to_s, default, &block) end end |
#has_key?(key) ⇒ Boolean Also known as: key?, include?
93 94 95 96 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 93 def has_key?(key) load_for_read! @delegate.key?(key.to_s) end |
#id ⇒ Object
69 70 71 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 69 def id [:id] end |
#inspect ⇒ Object
142 143 144 145 146 147 148 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 142 def inspect if loaded? super else "#<#{self.class}:0x#{(object_id << 1).to_s(16)} not yet loaded>" end end |
#keys ⇒ Object
100 101 102 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 100 def keys @delegate.keys end |
#loaded? ⇒ Boolean
155 156 157 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 155 def loaded? @loaded end |
#merge!(other) ⇒ Object
164 165 166 167 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 164 def merge!(other) load_for_write! @delegate.merge!(other) end |
#options ⇒ Object
73 74 75 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 73 def Options.find @env end |
#to_hash ⇒ Object
118 119 120 121 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 118 def to_hash load_for_read! @delegate.dup.delete_if { |_,v| v.nil? } end |
#update(hash) ⇒ Object
123 124 125 126 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 123 def update(hash) load_for_write! @delegate.update stringify_keys(hash) end |
#values ⇒ Object
104 105 106 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 104 def values @delegate.values end |