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
mongo_mapper-unstable-2010.07.16 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.15 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.14 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.13 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.12 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.09 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.08 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.07 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.06 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.05 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.02 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.07.01 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.06.30 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.06.29 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.06.28 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.06.25 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.06.24 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-unstable-2010.06.23 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-0.8.2 lib/mongo_mapper/plugins/querying/decorator.rb
mongo_mapper-0.8.1 lib/mongo_mapper/plugins/querying/decorator.rb