Sha256: 2926321547960b050b60eebd8556d72f793b8f81a92ba61082dffa9494c50ac5
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
module MongoMapper module Plugins module DynamicQuerying autoload :DynamicFinder, 'mongo_mapper/plugins/dynamic_querying/dynamic_finder' module ClassMethods def dynamic_find(finder, args) attributes = {} finder.attributes.each_with_index do |attr, index| attributes[attr] = args[index] end options = args.extract_options!.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 protected def method_missing(method, *args, &block) finder = DynamicFinder.new(method) if finder.found? dynamic_find(finder, args) else super end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pwnash-mongo_mapper-0.7.6 | lib/mongo_mapper/plugins/dynamic_querying.rb |