Class: ActionDispatch::Session::MongoStore::Session
- Inherits:
-
Object
- Object
- ActionDispatch::Session::MongoStore::Session
- Defined in:
- lib/mongo_session_store/mongo_store.rb
Instance Attribute Summary collapse
-
#_id ⇒ Object
Returns the value of attribute _id.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#data ⇒ Object
Returns the value of attribute data.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
- .collection ⇒ Object
- .database ⇒ Object
- .database=(database) ⇒ Object
- .last ⇒ Object
- .load(options = {}) ⇒ Object
- .reset_collection ⇒ Object
- .where(query = {}) ⇒ Object
Instance Method Summary collapse
- #collection ⇒ Object
- #destroy ⇒ Object
-
#initialize(options = {}) ⇒ Session
constructor
A new instance of Session.
- #save ⇒ Object
- #scope ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Session
Returns a new instance of Session.
10 11 12 13 14 15 |
# File 'lib/mongo_session_store/mongo_store.rb', line 10 def initialize( = {}) @_id = [:_id] @data = [:data] || BSON::Binary.new(Marshal.dump({}), :generic) @created_at = [:created_at] @updated_at = [:updated_at] end |
Instance Attribute Details
#_id ⇒ Object
Returns the value of attribute _id.
8 9 10 |
# File 'lib/mongo_session_store/mongo_store.rb', line 8 def _id @_id end |
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/mongo_session_store/mongo_store.rb', line 8 def created_at @created_at end |
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/mongo_session_store/mongo_store.rb', line 8 def data @data end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
8 9 10 |
# File 'lib/mongo_session_store/mongo_store.rb', line 8 def updated_at @updated_at end |
Class Method Details
.collection ⇒ Object
67 68 69 |
# File 'lib/mongo_session_store/mongo_store.rb', line 67 def self.collection @collection ||= database[MongoSessionStore.collection_name] end |
.database ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mongo_session_store/mongo_store.rb', line 55 def self.database if @database @database else raise "MongoStore needs a database, e.g. MongoStore::Session.database = Mongo::Client.new(['127.0.0.1:27017'], database: \"my_app_development\")" end end |
.database=(database) ⇒ Object
63 64 65 |
# File 'lib/mongo_session_store/mongo_store.rb', line 63 def self.database=(database) @database = database end |
.last ⇒ Object
51 52 53 |
# File 'lib/mongo_session_store/mongo_store.rb', line 51 def self.last where.last end |
.load(options = {}) ⇒ Object
17 18 19 20 |
# File 'lib/mongo_session_store/mongo_store.rb', line 17 def self.load( = {}) [:data] = ["data"] if ["data"] new() end |
.reset_collection ⇒ Object
71 72 73 |
# File 'lib/mongo_session_store/mongo_store.rb', line 71 def self.reset_collection @collection = nil end |
.where(query = {}) ⇒ Object
47 48 49 |
# File 'lib/mongo_session_store/mongo_store.rb', line 47 def self.where(query = {}) collection.find(query).map { |doc| load(doc) } end |
Instance Method Details
#collection ⇒ Object
75 76 77 |
# File 'lib/mongo_session_store/mongo_store.rb', line 75 def collection self.class.collection end |
#destroy ⇒ Object
26 27 28 |
# File 'lib/mongo_session_store/mongo_store.rb', line 26 def destroy scope.delete_one end |
#save ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mongo_session_store/mongo_store.rb', line 30 def save @created_at ||= Time.now @updated_at = Time.now attributes = { :data => BSON::Binary.new(@data, :generic), :created_at => @created_at, :updated_at => @updated_at } scope.replace_one(attributes, upsert: true) end |
#scope ⇒ Object
22 23 24 |
# File 'lib/mongo_session_store/mongo_store.rb', line 22 def scope collection.find(:_id => _id) end |