Sha256: b573ceca69d1c3f65713c8a6b65e8051e2b9532928440a1d68c2dcd481460003

Contents?: true

Size: 992 Bytes

Versions: 2

Compression:

Stored size: 992 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)
      return nil if conditions_or_id.nil?
      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

2 entries across 2 versions & 1 rubygems

Version Path
mongo_doc-0.6.28 lib/mongo_doc/finders.rb
mongo_doc-0.6.27 lib/mongo_doc/finders.rb