Module | Camping::Session |
In: |
lib/camping/session.rb
|
The Camping::Session module is designed to be mixed into your application or into specific controllers which require sessions. This module defines a service method which intercepts all requests handed to those controllers.
To get sessions working for your application:
If you are unfamiliar with the create method, see code.whytheluckystiff.net/camping/wiki/GiveUsTheCreateMethod.
This service method, when mixed into controllers, intercepts requests and wraps them with code to start and close the session. If a session isn‘t found in the database it is created. The @state variable is set and if it changes, it is saved back into the database.
# File lib/camping/session.rb, line 107 107: def service(*a) 108: session = Camping::Models::Session.persist @cookies 109: app = self.class.name.gsub(/^(\w+)::.+$/, '\1') 110: @state = (session[app] ||= Camping::H[]) 111: hash_before = Marshal.dump(@state).hash 112: s = super(*a) 113: if session 114: hash_after = Marshal.dump(@state).hash 115: unless hash_before == hash_after 116: session[app] = @state 117: session.save 118: end 119: end 120: s 121: end