Sha256: d232a8c1f7202da34879a83056c05ef7c3a89695c99a1a9a100057b6995975dc
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
require 'mongodoc/criteria' module MongoDoc module Finders def self.extended(base) base.extend(Criteria) unless base === Criteria end %w(count first last).each do |name| module_eval <<-RUBY # #{name.humanize} for this +Document+ class # # <tt>Person.#{name}</tt> def #{name} criteria.#{name} end RUBY end # Find a +Document+ based on id (+String+ or +Mongo::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 +Mongo::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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongodoc-0.2.4 | lib/mongodoc/finders.rb |