Class: Casino::Store
- Inherits:
-
Object
- Object
- Casino::Store
- Defined in:
- lib/casino/store.rb
Instance Attribute Summary collapse
-
#collection_class ⇒ Object
Returns the value of attribute collection_class.
-
#collection_name ⇒ Object
Returns the value of attribute collection_name.
Instance Method Summary collapse
- #collection ⇒ Object
- #criteria ⇒ Object
-
#initialize(document_class) ⇒ Store
constructor
A new instance of Store.
- #merge(*documents) ⇒ Object
- #query ⇒ Object
Constructor Details
#initialize(document_class) ⇒ Store
Returns a new instance of Store.
12 13 14 15 |
# File 'lib/casino/store.rb', line 12 def initialize(document_class) self.collection_class = document_class self.collection_name = document_class.collection_name end |
Instance Attribute Details
#collection_class ⇒ Object
Returns the value of attribute collection_class.
3 4 5 |
# File 'lib/casino/store.rb', line 3 def collection_class @collection_class end |
#collection_name ⇒ Object
Returns the value of attribute collection_name.
3 4 5 |
# File 'lib/casino/store.rb', line 3 def collection_name @collection_name end |
Instance Method Details
#collection ⇒ Object
17 18 19 |
# File 'lib/casino/store.rb', line 17 def collection @collection ||= session[collection_name.to_sym] end |
#criteria ⇒ Object
33 34 35 |
# File 'lib/casino/store.rb', line 33 def criteria @criteria ||= collection_class.scoped end |
#merge(*documents) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/casino/store.rb', line 25 def merge(*documents) documents.each do |document| document = document.mongoize criteria = find _id: document['_id'] criteria.upsert document end end |
#query ⇒ Object
21 22 23 |
# File 'lib/casino/store.rb', line 21 def query @query ||= collection.find end |