Module: Glamping::Session
- Defined in:
- lib/glamping/session.rb
Overview
-
Sessions are loaded from DB at every requests
Instance Method Summary collapse
-
#service(*a) ⇒ Object
This
service
method, when mixed into controllers, intercepts requests and wraps them with code to start and close the session.
Instance Method Details
#service(*a) ⇒ Object
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.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/glamping/session.rb', line 116 def service(*a) session = Glamping::Models::Session.persist @cookies app = self.class.name.gsub(/^(\w+)::.+$/, '\1') @state = (session[app] ||= Glamping::H[]) hash_before = Marshal.dump(@state).hash return super(*a) ensure if session hash_after = Marshal.dump(@state).hash unless hash_before == hash_after session[app] = @state session.save end end end |