Module: Mongo::Operation::Idable Private
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/mongo/operation/shared/idable.rb |
Overview
Shared behavior of operations that require its documents to each have an id.
Constant Summary
-
ID_GENERATOR =
The option for a custom id generator.
:id_generator.freeze
Instance Method Summary
- #documents Internal use only
- #ensure_ids(documents) private Internal use only
- #has_id?(doc) ⇒ Boolean private Internal use only
- #id(doc) private Internal use only
-
#id_generator ⇒ IdGenerator
private
Internal use only
Get the id generator.
Instance Method Details
#documents
# File 'lib/mongo/operation/shared/idable.rb', line 27
def documents @documents ||= ensure_ids(super) end
#ensure_ids(documents) (private)
# File 'lib/mongo/operation/shared/idable.rb', line 58
def ensure_ids(documents) @ids = [] documents.collect do |doc| doc_with_id = has_id?(doc) ? doc : doc.merge(_id: id_generator.generate) @ids << id(doc_with_id) doc_with_id end end
#has_id?(doc) ⇒ Boolean
(private)
# File 'lib/mongo/operation/shared/idable.rb', line 54
def has_id?(doc) !!id(doc) end
#id(doc) (private)
# File 'lib/mongo/operation/shared/idable.rb', line 50
def id(doc) doc.respond_to?(:id) ? doc.id : (doc['_id'] || doc[:_id]) end
#id_generator ⇒ IdGenerator
(private)
Get the id generator.
# File 'lib/mongo/operation/shared/idable.rb', line 46
def id_generator @id_generator ||= (spec[ID_GENERATOR] || Operation::ObjectIdGenerator.new) end