Class: ActionDispatch::Session::MongoStore::Session
- Inherits:
-
Object
- Object
- ActionDispatch::Session::MongoStore::Session
show all
- Defined in:
- lib/mongo_session_store/mongo_store.rb
Defined Under Namespace
Classes: NoMongoClientError
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Session
Returns a new instance of Session.
54
55
56
57
58
59
|
# 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
|
Class Attribute Details
.database ⇒ Object
25
26
27
28
29
30
31
|
# 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
|
Instance Attribute Details
#_id ⇒ Object
Returns the value of attribute _id.
52
53
54
|
# File 'lib/mongo_session_store/mongo_store.rb', line 52
def _id
@_id
end
|
#created_at ⇒ Object
Returns the value of attribute created_at.
52
53
54
|
# File 'lib/mongo_session_store/mongo_store.rb', line 52
def created_at
@created_at
end
|
#data ⇒ Object
Returns the value of attribute data.
52
53
54
|
# File 'lib/mongo_session_store/mongo_store.rb', line 52
def data
@data
end
|
#updated_at ⇒ Object
Returns the value of attribute updated_at.
52
53
54
|
# File 'lib/mongo_session_store/mongo_store.rb', line 52
def updated_at
@updated_at
end
|
Class Method Details
.collection ⇒ Object
33
34
35
|
# File 'lib/mongo_session_store/mongo_store.rb', line 33
def collection
@collection ||= database[MongoSessionStore.collection_name]
end
|
.load(options = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# 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
|
.reset_collection ⇒ Object
37
38
39
|
# File 'lib/mongo_session_store/mongo_store.rb', line 37
def reset_collection
@collection = nil
end
|
.where(query = {}) ⇒ Object
21
22
23
|
# File 'lib/mongo_session_store/mongo_store.rb', line 21
def where(query = {})
collection.find(query).map { |doc| load(doc) }
end
|
Instance Method Details
#destroy ⇒ Object
68
69
70
|
# File 'lib/mongo_session_store/mongo_store.rb', line 68
def destroy
scope.delete_one
end
|
#save ⇒ Object
61
62
63
64
65
66
|
# 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
|