Sha256: c5e0b1a9f0ac23b22e808d731847d62df3b68e66889674de64bf63534b0eb304
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
# encoding: UTF-8 module MongoMapper module Plugins module Querying module Decorator include MongoMapper::Plugins::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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongo_mapper-0.8.0 | lib/mongo_mapper/plugins/querying/decorator.rb |