Class: ActionDispatch::Session::CodeIgniterStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- ActionDispatch::Session::CodeIgniterStore
- Defined in:
- lib/action_dispatch/session/code_igniter_store.rb
Instance Method Summary collapse
-
#delete_session(req, sid, _options) ⇒ String
Deletes then creates a new session in the database.
-
#extract_session_id(req) ⇒ String?
Tries to find the session ID in the requests cookies.
-
#find_session(req, sid) ⇒ Array<String, Object>
Finds an existing session or creates a new one.
-
#initialize(app, options = {}) ⇒ CodeIgniterStore
constructor
A new instance of CodeIgniterStore.
-
#write_session(req, sid, session, _options) ⇒ String
Writes the session information to the database.
Constructor Details
#initialize(app, options = {}) ⇒ CodeIgniterStore
9 10 11 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 9 def initialize(app, ={}) super(app, { key: 'default_pyrocms' }.merge()) end |
Instance Method Details
#delete_session(req, sid, _options) ⇒ String
Deletes then creates a new session in the database.
52 53 54 55 56 57 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 52 def delete_session(req, sid, ) # Get the current database record for this session then delete it. find_session_model(req, sid).delete # Generate a new one and return it's ID find_session_model(req).session_id end |
#extract_session_id(req) ⇒ String?
Tries to find the session ID in the requests cookies.
63 64 65 66 67 68 69 70 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 63 def extract_session_id(req) sid = req.[@key] # returning `nil` just causes a new ID to be generated. return if sid.nil? # sometimes the cookie contains just the session ID. return sid if sid.size <= 32 Firebug.(sid)[:session_id] end |
#find_session(req, sid) ⇒ Array<String, Object>
Finds an existing session or creates a new one.
18 19 20 21 22 23 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 18 def find_session(req, sid) model = find_session_model(req, sid) # +Rack::Session::Abstract::Persisted#load_session+ expects this to return an Array with the first value being # the session ID and the second the actual session data. [model.session_id, model.user_data] end |
#write_session(req, sid, session, _options) ⇒ String
Writes the session information to the database.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/action_dispatch/session/code_igniter_store.rb', line 32 def write_session(req, sid, session, ) model = find_session_model(req, sid) model_params = { session_id: model.session_id, user_agent: req.user_agent || '', # user_agent can't be null ip_address: req.remote_ip || '', # ip_address can't be null user_data: session } # Returning false will cause Rack to output a warning. return false unless model.update(model_params) # Return the encrypted cookie format of the data. Rack sets this value as the cookie in the response model. end |