Module: Mongo::Object::CollectionHelper
- Defined in:
- lib/mongo/object/collection_helper.rb
Instance Method Summary collapse
- #create!(*args) ⇒ Object
-
#create_with_object(doc, options = {}) ⇒ Object
CRUD.
- #delete!(*args) ⇒ Object
- #delete_with_object(*args) ⇒ Object
- #each(selector = {}, options = {}, &block) ⇒ Object
-
#first(selector = {}, options = {}) ⇒ Object
Querying.
- #save!(*args) ⇒ Object
- #save_with_object(doc, options = {}) ⇒ Object
- #update!(*args) ⇒ Object
- #update_with_object(*args) ⇒ Object
Instance Method Details
#create!(*args) ⇒ Object
40 41 42 |
# File 'lib/mongo/object/collection_helper.rb', line 40 def create! *args create(*args) || raise(Mongo::Error, "can't create #{args.inspect}!") end |
#create_with_object(doc, options = {}) ⇒ Object
CRUD.
4 5 6 7 8 9 10 |
# File 'lib/mongo/object/collection_helper.rb', line 4 def create_with_object doc, = {} if doc.is_a? ::Mongo::Object doc.create_object self, else create_without_object doc, end end |
#delete!(*args) ⇒ Object
52 53 54 |
# File 'lib/mongo/object/collection_helper.rb', line 52 def delete! *args delete(*args) || raise(Mongo::Error, "can't delete #{args.inspect}!") end |
#delete_with_object(*args) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/mongo/object/collection_helper.rb', line 30 def delete_with_object *args if args.first.is_a? ::Mongo::Object doc, = args ||= {} doc.delete_object self, else delete_without_object *args end end |
#each(selector = {}, options = {}, &block) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mongo/object/collection_helper.rb', line 68 def each selector = {}, = {}, &block = .clone if .delete(:object) == false super selector, , &block else super selector, do |doc| block.call build(doc) end end end |
#first(selector = {}, options = {}) ⇒ Object
Querying.
58 59 60 61 62 63 64 65 66 |
# File 'lib/mongo/object/collection_helper.rb', line 58 def first selector = {}, = {} = .clone if .delete(:object) == false super selector, else doc = super(selector, ) build doc end end |
#save!(*args) ⇒ Object
48 49 50 |
# File 'lib/mongo/object/collection_helper.rb', line 48 def save! *args save(*args) || raise(Mongo::Error, "can't save #{args.inspect}!") end |
#save_with_object(doc, options = {}) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/mongo/object/collection_helper.rb', line 22 def save_with_object doc, = {} if doc.is_a? ::Mongo::Object doc.save_object self, else save_without_object doc, end end |
#update!(*args) ⇒ Object
44 45 46 |
# File 'lib/mongo/object/collection_helper.rb', line 44 def update! *args update(*args) || raise(Mongo::Error, "can't update #{args.inspect}!") end |
#update_with_object(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/mongo/object/collection_helper.rb', line 12 def update_with_object *args if args.first.is_a? ::Mongo::Object doc, = args ||= {} doc.update_object self, else update_without_object *args end end |