Sha256: e4556f1b0b5238f6d2471b1d5e72f7b6b4d0ecc2f8ae3d5f6ba5fc9450f0e5dc

Contents?: true

Size: 950 Bytes

Versions: 15

Compression:

Stored size: 950 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(:conditions => {:age.gt => 25}, :order_by => [[:name,
    # :asc]])</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

15 entries across 15 versions & 1 rubygems

Version Path
mongo_doc-0.6.26 lib/mongo_doc/finders.rb
mongo_doc-0.6.25 lib/mongo_doc/finders.rb
mongo_doc-0.6.23 lib/mongo_doc/finders.rb
mongo_doc-0.6.22 lib/mongo_doc/finders.rb
mongo_doc-0.6.21 lib/mongo_doc/finders.rb
mongo_doc-0.6.20 lib/mongo_doc/finders.rb
mongo_doc-0.6.19 lib/mongo_doc/finders.rb
mongo_doc-0.6.18 lib/mongo_doc/finders.rb
mongo_doc-0.6.17 lib/mongo_doc/finders.rb
mongo_doc-0.6.16 lib/mongo_doc/finders.rb
mongo_doc-0.6.15 lib/mongo_doc/finders.rb
mongo_doc-0.6.14 lib/mongo_doc/finders.rb
mongo_doc-0.6.13 lib/mongo_doc/finders.rb
mongo_doc-0.6.12 lib/mongo_doc/finders.rb
mongo_doc-0.6.11 lib/mongo_doc/finders.rb