Sha256: b70079dbcaeaa0e4ba1d89434e6b38ccfebd3a88ad2b88f275b54e46f3c2137d

Contents?: true

Size: 1.07 KB

Versions: 59

Compression:

Stored size: 1.07 KB

Contents

# encoding: UTF-8
require 'mongo_mapper/plugins/dynamic_querying/dynamic_finder'

module MongoMapper
  module Plugins
    module DynamicQuerying
      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

59 entries across 59 versions & 7 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/dynamic_querying.rb
ign-mongo_mapper-0.8.6.2 lib/mongo_mapper/plugins/dynamic_querying.rb
ign-mongo_mapper-0.8.6.1 lib/mongo_mapper/plugins/dynamic_querying.rb
ssherman-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-0.8.6 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-0.8.5 lib/mongo_mapper/plugins/dynamic_querying.rb
honkster-mongo_mapper-0.8.4 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-0.8.4 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.19 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/plugins/dynamic_querying.rb
mongo_mapper-0.8.3 lib/mongo_mapper/plugins/dynamic_querying.rb