Sha256: a951371cf2dbaf4b6a8bc6d1a61b29293d7593551604faf61572014e11bd36e8

Contents?: true

Size: 908 Bytes

Versions: 14

Compression:

Stored size: 908 Bytes

Contents

require 'mongo_doc/criteria'

module MongoDoc
  module Finders
    def self.extended(base)
      base.extend(Criteria) unless base === Criteria
    end

    # Find a +Document+ based on id (+String+ or +BSON::ObjectID+)
    #
    # <tt>Person.find('1')</tt>
    # <tt>Person.find(obj_id_1, obj_id_2)</tt>
    def find(*args)
      criteria.id(*args)
    end
    #
    # Find all +Document+s in the collections
    #
    # <tt>Person.find_all</tt>
    def find_all
      criteria
    end

    # Find a +Document+ based on id (+String+ or +BSON::ObjectID+)
    # or conditions
    #
    # <tt>Person.find_one('1')</tt>
    # <tt>Person.find_one(:where => {:age.gt > 25})</tt>
    def find_one(conditions_or_id)
      if Hash === conditions_or_id
        Mongoid::Criteria.translate(self, conditions_or_id).one
      else
        Mongoid::Criteria.translate(self, conditions_or_id)
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
mongo_doc-0.6.10 lib/mongo_doc/finders.rb
mongo_doc-0.6.9 lib/mongo_doc/finders.rb
mongo_doc-0.6.8 lib/mongo_doc/finders.rb
mongo_doc-0.6.7 lib/mongo_doc/finders.rb
mongo_doc-0.6.6 lib/mongo_doc/finders.rb
mongo_doc-0.6.5 lib/mongo_doc/finders.rb
mongo_doc-0.6.4 lib/mongo_doc/finders.rb
mongo_doc_rails2-0.6.2 lib/mongo_doc/finders.rb
mongo_doc-0.6.3 lib/mongo_doc/finders.rb
mongo_doc-0.6.2 lib/mongo_doc/finders.rb
mongo_doc-0.6.1 lib/mongo_doc/finders.rb
mongo_doc-0.6.0 lib/mongo_doc/finders.rb
mongo_doc_rails2-0.6.1 lib/mongo_doc/finders.rb
mongo_doc-0.5.5 lib/mongo_doc/finders.rb