Module: MongoMapper::Plugins::DynamicQuerying::ClassMethods
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/mongo_mapper/plugins/dynamic_querying.rb', line 30
def method_missing(method, *args, &block)
finder = DynamicFinder.new(method)
if finder.found?
dynamic_find(finder, args)
else
super
end
end
|
Instance Method Details
#dynamic_find(finder, args) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/mongo_mapper/plugins/dynamic_querying.rb', line 7
def dynamic_find(finder, args)
attributes = {}
finder.attributes.each_with_index do |attr, index|
attributes[attr] = args[index]
end
options = args..merge(attributes)
if result = send(finder.finder, options)
result
else
if finder.raise?
raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}"
end
if finder.instantiator
self.send(finder.instantiator, attributes)
end
end
end
|