Sha256: 7a735219631d99558f48fa8fa2e1eea020eb2c1c24be7f0029daacf531abdcbe

Contents?: true

Size: 1.16 KB

Versions: 60

Compression:

Stored size: 1.16 KB

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Querying
      module Decorator
        include DynamicQuerying::ClassMethods

        def model(model=nil)
          return @model if model.nil?
          @model = model
          self
        end

        def find!(*ids)
          raise DocumentNotFound, "Couldn't find without an ID" if ids.size == 0

          find(*ids).tap do |result|
            if result.nil? || ids.size != Array(result).size
              raise DocumentNotFound, "Couldn't find all of the ids (#{ids.join(',')}). Found #{Array(result).size}, but was expecting #{ids.size}"
            end
          end
        end

        def all(opts={})
          super.map { |doc| model.load(doc) }
        end

        def first(opts={})
          model.load(super)
        end

        def last(opts={})
          model.load(super)
        end

        private
          def method_missing(method, *args, &block)
            return super unless model.respond_to?(method)
            result = model.send(method, *args, &block)
            return super unless result.is_a?(Plucky::Query)
            merge(result)
          end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 7 rubygems

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