Class: Mongoid::Relations::Referenced::Batch::Insert
- Defined in:
- lib/mongoid/relations/referenced/batch/insert.rb
Overview
Handles all the batch insert collection.
Instance Attribute Summary collapse
-
#documents ⇒ Object
Returns the value of attribute documents.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#consume(document, options = {}) ⇒ Object
Consumes an execution that was supposed to hit the database, but is now being deferred to later in favor of a single batch insert.
-
#consumed? ⇒ true, false
Has this operation consumed any executions?.
-
#execute(collection) ⇒ Object
Execute the batch insert operation on the collection.
Instance Attribute Details
#documents ⇒ Object
Returns the value of attribute documents.
9 10 11 |
# File 'lib/mongoid/relations/referenced/batch/insert.rb', line 9 def documents @documents end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/mongoid/relations/referenced/batch/insert.rb', line 9 def @options end |
Instance Method Details
#consume(document, options = {}) ⇒ Object
Consumes an execution that was supposed to hit the database, but is now being deferred to later in favor of a single batch insert.
23 24 25 26 |
# File 'lib/mongoid/relations/referenced/batch/insert.rb', line 23 def consume(document, = {}) @consumed, @options = true, (@documents ||= []).push(document) end |
#consumed? ⇒ true, false
Has this operation consumed any executions?
36 37 38 |
# File 'lib/mongoid/relations/referenced/batch/insert.rb', line 36 def consumed? !!@consumed end |
#execute(collection) ⇒ Object
Execute the batch insert operation on the collection.
48 49 50 51 52 |
# File 'lib/mongoid/relations/referenced/batch/insert.rb', line 48 def execute(collection) if collection && consumed? collection.insert(documents, ) end end |