Module: Ext::OgSession::Base

Defined in:
lib/ext/og_session.rb

Instance Method Summary collapse

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.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ext/og_session.rb', line 60

def service(*a)
  session = OgSession.persist @cookies
  app = self.class.name.gsub(/^(\w+)::.+$/, '\1')
  @state = (session[app] ||= Camping::H[])
  hash_before = Marshal.dump(@state).hash
  s = super(*a)
  if session
    hash_after = Marshal.dump(@state).hash
    unless hash_before == hash_after
      session[app] = @state
      session.save
    end
  end
  s
end