Class: Casino::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/casino/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_classObject

Returns the value of attribute collection_class.



3
4
5
# File 'lib/casino/store.rb', line 3

def collection_class
  @collection_class
end

#collection_nameObject

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

#collectionObject



17
18
19
# File 'lib/casino/store.rb', line 17

def collection
  @collection ||= session[collection_name.to_sym]
end

#criteriaObject



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

#queryObject



21
22
23
# File 'lib/casino/store.rb', line 21

def query
  @query ||= collection.find
end