123456789_123456789_123456789_123456789_123456789_

Module: Mongo::BulkWrite::Validatable Private

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/mongo/bulk_write/validatable.rb

Overview

Defines behavior around validations.

Since:

  • 2.1.0

Instance Method Summary

Instance Method Details

#validate(name, document) ⇒ Hash, BSON::Document

Validate the document.

Examples:

Validate the document.

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

Parameters:

  • name (Symbol)

    The operation name.

  • document (Hash, BSON::Document)

    The document.

Returns:

  • (Hash, BSON::Document)

    The document.

Raises:

  • (InvalidBulkOperation)

    If not valid.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/validatable.rb', line 43

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

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

#validate_document(name, document) (private)

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/validatable.rb', line 61

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) (private)

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/bulk_write/validatable.rb', line 69

def validate_operation(name)
  unless Transformable::MAPPERS.key?(name)
    raise Error::InvalidBulkOperationType.new(name)
  end
end