Module: MongoMapper::Finders Private
- Defined in:
- lib/novelys_mongo_mapper/dynamic_finder.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 31 32 33 34 |
# File 'lib/novelys_mongo_mapper/dynamic_finder.rb', line 26 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/novelys_mongo_mapper/dynamic_finder.rb', line 4 def dynamic_find(finder, args) attributes = {} finder.attributes.each_with_index do |attr, index| attributes[attr] = args[index] end = args..merge(attributes) if result = send(finder.finder, ) 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 |