class ActionDispatch::Session::MongoStore::Session

Attributes

database[W]
_id[RW]
created_at[RW]
data[RW]
updated_at[RW]

Public Class Methods

collection() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 33
def collection
  @collection ||= database[MongoSessionStore.collection_name]
end
database() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 25
def database
  return @database if @database

  raise NoMongoClientError, "MongoStore needs a database, e.g. "\
    "MongoStore::Session.database = Mongo::Client.new("\
    "[\"127.0.0.1:27017\"], database: \"my_app_development\")"
end
load(options = {}) click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 10
def load(options = {})
  options[:data] = options["data"] if options["data"]
  options[:data] =
    if options[:data]
      unpack(options[:data])
    else
      {}
    end
  new(options)
end
new(options = {}) click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 54
def initialize(options = {})
  @_id        = options[:_id]
  @data       = options[:data]
  @created_at = options[:created_at]
  @updated_at = options[:updated_at]
end
reset_collection() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 37
def reset_collection
  @collection = nil
end
where(query = {}) click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 21
def where(query = {})
  collection.find(query).map { |doc| load(doc) }
end

Private Class Methods

unpack(packed) click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 43
def unpack(packed)
  return unless packed
  data = packed.respond_to?(:data) ? packed.data : packed.to_s
  Marshal.load(StringIO.new(data))
end

Public Instance Methods

destroy() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 68
def destroy
  scope.delete_one
end
save() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 61
def save
  @created_at ||= Time.now.utc
  @updated_at = Time.now.utc

  scope.replace_one(attributes_for_save, :upsert => true)
end

Private Instance Methods

attributes_for_save() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 78
def attributes_for_save
  {
    :data => pack(data),
    :created_at => created_at,
    :updated_at => updated_at
  }
end
collection() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 74
def collection
  self.class.collection
end
pack(data) click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 90
def pack(data)
  BSON::Binary.new(Marshal.dump(data || {}), :generic)
end
scope() click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 86
def scope
  collection.find(:_id => _id)
end
unpack(packed) click to toggle source
# File lib/mongo_session_store/mongo_store.rb, line 94
def unpack(packed)
  self.class.unpack(packed)
end