module Mongo::BulkWrite::Validatable

Defines behavior around validations.

@api private

@since 2.1.0

Public Instance Methods

validate(name, document) click to toggle source

Validate the document.

@api private

@example Validate the document.

validatable.validate(:insert_one, { _id: 0 })

@param [ Symbol ] name The operation name. @param [ Hash, BSON::Document ] document The document.

@raise [ InvalidBulkOperation ] If not valid.

@return [ Hash, BSON::Document ] The document.

@since 2.1.0

# File lib/mongo/bulk_write/validatable.rb, line 40
def validate(name, document)
  validate_operation(name)
  validate_document(name, document)
  if document.respond_to?(:keys) && (document[:collation] || document[Operation::COLLATION])
    @has_collation = true
  end

  if document.respond_to?(:keys) && document[:array_filters]
    @has_array_filters = true
  end
end

Private Instance Methods

validate_document(name, document) click to toggle source
# File lib/mongo/bulk_write/validatable.rb, line 54
def validate_document(name, document)
  if document.respond_to?(:keys) || document.respond_to?(:data)
    document
  else
    raise Error::InvalidBulkOperation.new(name, document)
  end
end
validate_operation(name) click to toggle source
# File lib/mongo/bulk_write/validatable.rb, line 62
def validate_operation(name)
  unless Transformable::MAPPERS.key?(name)
    raise Error::InvalidBulkOperationType.new(name)
  end
end