Module: MongoMapper::Plugins::Querying::Decorator
Instance Method Summary
collapse
#dynamic_find
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 37
def method_missing(method, *args, &block)
return super unless model.respond_to?(method)
result = model.send(method, *args, &block)
return super unless result.is_a?(Plucky::Query)
merge(result)
end
|
Instance Method Details
#all(opts = {}) ⇒ Object
24
25
26
|
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 24
def all(opts={})
super.map { |doc| model.load(doc) }
end
|
#find!(*ids) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 14
def find!(*ids)
raise DocumentNotFound, "Couldn't find without an ID" if ids.size == 0
find(*ids).tap do |result|
if result.nil? || ids.size != Array(result).size
raise DocumentNotFound, "Couldn't find all of the ids (#{ids.join(',')}). Found #{Array(result).size}, but was expecting #{ids.size}"
end
end
end
|
#first(opts = {}) ⇒ Object
28
29
30
|
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 28
def first(opts={})
model.load(super)
end
|
#last(opts = {}) ⇒ Object
32
33
34
|
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 32
def last(opts={})
model.load(super)
end
|
#model(model = nil) ⇒ Object
8
9
10
11
12
|
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 8
def model(model=nil)
return @model if model.nil?
@model = model
self
end
|