Class: MongoScope::ScopedCollection
Instance Attribute Summary collapse
Instance Method Summary
collapse
#count, #to_scoped
#raw_scope, #scope_eq
Constructor Details
Returns a new instance of ScopedCollection.
74
75
76
77
|
# File 'lib/mongo_scope.rb', line 74
def initialize(scope_ops,coll)
self.scope_obj = (scope_ops ? Scope.new(scope_ops) : nil)
self.coll = coll
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &b) ⇒ Object
93
94
95
|
# File 'lib/mongo_scope.rb', line 93
def method_missing(sym,*args,&b)
coll.send(sym,*args,&b)
end
|
Instance Attribute Details
#coll ⇒ Object
72
73
74
|
# File 'lib/mongo_scope.rb', line 72
def coll
@coll
end
|
#scope_obj ⇒ Object
72
73
74
|
# File 'lib/mongo_scope.rb', line 72
def scope_obj
@scope_obj
end
|
Instance Method Details
#each(&b) ⇒ Object
96
97
98
|
# File 'lib/mongo_scope.rb', line 96
def each(&b)
coll.each(&b) end
|
#find(selector = {}, options = {}) ⇒ Object
83
84
85
|
# File 'lib/mongo_scope.rb', line 83
def find(selector={},options={})
ScopedCursor.new(:cursor => coll.find(scoped_ops(selector),options))
end
|
#find_one(selector = {}, options = {}) ⇒ Object
86
87
88
89
|
# File 'lib/mongo_scope.rb', line 86
def find_one(selector={},options={})
res = coll.find_one(scoped_ops(selector),options)
res ? MongoRow.new(res) : res
end
|
#group(k, filter, *args) ⇒ Object
99
100
101
102
|
# File 'lib/mongo_scope.rb', line 99
def group(k,filter,*args)
filter = scoped_ops(filter || {})
coll.group(k,filter,*args)
end
|
#remove(ops = {}) ⇒ Object
90
91
92
|
# File 'lib/mongo_scope.rb', line 90
def remove(ops={})
coll.remove(scoped_ops(ops))
end
|
#scoped_ops(ops) ⇒ Object
78
79
80
81
82
|
# File 'lib/mongo_scope.rb', line 78
def scoped_ops(ops)
return ops unless scope_obj
ops = {'_id' => ops} unless ops.kind_of?(Hash)
ops.merge(scope_obj.find_ops)
end
|