module Mongo::BulkWrite::Validatable

Defines behaviour 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)
end

Private Instance Methods

validate_document(name, document) click to toggle source
# File lib/mongo/bulk_write/validatable.rb, line 47
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 55
def validate_operation(name)
  unless Transformable::MAPPERS.key?(name)
    raise Error::InvalidBulkOperationType.new(name)
  end
end