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
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #destroy ⇒ Object
- #empty? ⇒ Boolean
- #exists? ⇒ Boolean
- #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.
58 59 60 61 62 63 64 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 58 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
10 11 12 13 14 15 16 17 18 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 10 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
20 21 22 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 20 def self.find(env) env[ENV_SESSION_KEY] end |
.set(env, session) ⇒ Object
24 25 26 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 24 def self.set(env, session) env[ENV_SESSION_KEY] = session end |
Instance Method Details
#[](key) ⇒ Object
85 86 87 88 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 85 def [](key) load_for_read! @delegate[key.to_s] end |
#[]=(key, value) ⇒ Object
105 106 107 108 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 105 def []=(key, value) load_for_write! @delegate[key.to_s] = value end |
#clear ⇒ Object
110 111 112 113 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 110 def clear load_for_write! @delegate.clear end |
#delete(key) ⇒ Object
125 126 127 128 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 125 def delete(key) load_for_write! @delegate.delete key.to_s end |
#destroy ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 74 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
147 148 149 150 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 147 def empty? load_for_read! @delegate.empty? end |
#exists? ⇒ Boolean
138 139 140 141 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 138 def exists? return @exists unless @exists.nil? @exists = @by.send(:session_exists?, @env) end |
#has_key?(key) ⇒ Boolean Also known as: key?, include?
90 91 92 93 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 90 def has_key?(key) load_for_read! @delegate.key?(key.to_s) end |
#id ⇒ Object
66 67 68 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 66 def id [:id] end |
#inspect ⇒ Object
130 131 132 133 134 135 136 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 130 def inspect if loaded? super else "#<#{self.class}:0x#{(object_id << 1).to_s(16)} not yet loaded>" end end |
#keys ⇒ Object
97 98 99 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 97 def keys @delegate.keys end |
#loaded? ⇒ Boolean
143 144 145 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 143 def loaded? @loaded end |
#merge!(other) ⇒ Object
152 153 154 155 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 152 def merge!(other) load_for_write! @delegate.merge!(other) end |
#options ⇒ Object
70 71 72 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 70 def Options.find @env end |
#to_hash ⇒ Object
115 116 117 118 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 115 def to_hash load_for_read! @delegate.dup.delete_if { |_,v| v.nil? } end |
#update(hash) ⇒ Object
120 121 122 123 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 120 def update(hash) load_for_write! @delegate.update stringify_keys(hash) end |
#values ⇒ Object
101 102 103 |
# File 'actionpack/lib/action_dispatch/request/session.rb', line 101 def values @delegate.values end |