Class: Ext::OgSession::Models::OgSession
- Defined in:
- lib/ext/og_session.rb
Constant Summary collapse
- RAND_CHARS =
[*'A'..'Z'] + [*'0'..'9'] + [*'a'..'z']
Class Method Summary collapse
-
.generate(cookies) ⇒ Object
Generates a new session ID and creates a row for the new session in the database.
-
.persist(cookies) ⇒ Object
Gets the existing session based on the
camping_sid
available in cookies.
Instance Method Summary collapse
Class Method Details
.generate(cookies) ⇒ Object
Generates a new session ID and creates a row for the new session in the database.
33 34 35 36 37 38 39 |
# File 'lib/ext/og_session.rb', line 33 def self.generate rand_max = RAND_CHARS.size sid = (0...32).inject("") { |ret,_| ret << RAND_CHARS[rand(rand_max)] } sess = self.create :hashid => sid, :ivars => Camping::H[] .camping_sid = sess.hashid sess end |
.persist(cookies) ⇒ Object
Gets the existing session based on the camping_sid
available in cookies. If none is found, generates a new session.
43 44 45 46 47 48 49 50 51 |
# File 'lib/ext/og_session.rb', line 43 def self.persist if .camping_sid session = self.find_by_hashid .camping_sid end unless session session = self.generate end session end |