Sha256: 8c34147357d49e4a5c494e24bffaec0303a274ad45048d0b0ac587acbb486554

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

# Copyright (C) 2015 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Mongo
  class BulkWrite

    # Defines behaviour around validations.
    #
    # @api private
    #
    # @since 2.1.0
    module Validatable

      # 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
      def validate(name, document)
        validate_operation(name)
        validate_document(name, document)
      end

      private

      def validate_document(name, document)
        if document.respond_to?(:keys) || document.respond_to?(:data)
          document
        else
          raise Error::InvalidBulkOperation.new(name, document)
        end
      end

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

Version data entries

16 entries across 15 versions & 3 rubygems

Version Path
mongo-2.2.7 lib/mongo/bulk_write/validatable.rb
mongo-2.2.6 lib/mongo/bulk_write/validatable.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongo-2.2.5/lib/mongo/bulk_write/validatable.rb
mongo-2.2.5 lib/mongo/bulk_write/validatable.rb
mongo-2.2.4 lib/mongo/bulk_write/validatable.rb
mongo-2.2.3 lib/mongo/bulk_write/validatable.rb
mongo-2.2.2 lib/mongo/bulk_write/validatable.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mongo-2.2.1/lib/mongo/bulk_write/validatable.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mongo-2.2.1/lib/mongo/bulk_write/validatable.rb
mongo-2.2.1 lib/mongo/bulk_write/validatable.rb
mongo-2.2.0 lib/mongo/bulk_write/validatable.rb
mongo-2.2.0.rc0 lib/mongo/bulk_write/validatable.rb
mongo-2.1.2 lib/mongo/bulk_write/validatable.rb
mongo-2.1.1 lib/mongo/bulk_write/validatable.rb
mongo-2.1.0 lib/mongo/bulk_write/validatable.rb
mongo-2.1.0.rc0 lib/mongo/bulk_write/validatable.rb