46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/mongo_mapper.rb', line 46
def dynamic_find(finder, args)
attributes = {}
find_options = args..deep_merge(:conditions => attributes)
finder.attributes.each_with_index do |attr, index|
attributes[attr] = args[index]
end
result = find(finder.finder, find_options)
if result.nil?
if finder.bang
raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}"
end
if finder.instantiator
self.send(finder.instantiator, attributes)
end
else
result
end
end
|