Class: Mongo::DelegatingCollection

Inherits:
Object
  • Object
show all
Includes:
CollMod, FromHash
Defined in:
lib/mongo_delegate/delegating_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CollMod

#count

Instance Attribute Details

#localObject

Returns the value of attribute local.



14
15
16
# File 'lib/mongo_delegate/delegating_collection.rb', line 14

def local
  @local
end

#remoteObject

Returns the value of attribute remote.



14
15
16
# File 'lib/mongo_delegate/delegating_collection.rb', line 14

def remote
  @remote
end

Instance Method Details

#collsObject



24
25
26
# File 'lib/mongo_delegate/delegating_collection.rb', line 24

def colls
  [local,remote]
end

#find(selector = {}, options = {}) ⇒ Object



15
16
17
# File 'lib/mongo_delegate/delegating_collection.rb', line 15

def find(selector={},options={})
  CompositeCursor.new(:colls => [local,remote],:selector => selector, :options => options)  
end

#find_one(selector = {}, options = {}) ⇒ Object



18
19
20
# File 'lib/mongo_delegate/delegating_collection.rb', line 18

def find_one(selector = {},options = {})
  find(selector,options.merge(:limit => 1)).first
end

#removeObject



21
22
23
# File 'lib/mongo_delegate/delegating_collection.rb', line 21

def remove
  colls.each { |x| x.remove }
end

#save(d) ⇒ Object



27
28
29
30
# File 'lib/mongo_delegate/delegating_collection.rb', line 27

def save(d)
  d = d.merge('_duplicate' => true) if d['_id'] && remote.find_one('_id' => d['_id'])
  local.save(d)
end