Sha256: f50144233972048211c4ae9e897affc0984caf3bcc62f23273ac1e897717ab21

Contents?: true

Size: 878 Bytes

Versions: 3

Compression:

Stored size: 878 Bytes

Contents

module AvroPatches
  module LogicalTypes
    module SchemaValidatorPatch
      def validate!(expected_schema, logical_datum, encoded = false)
        result = Avro::SchemaValidator::Result.new
        validate_recursive(expected_schema, logical_datum, Avro::SchemaValidator::ROOT_IDENTIFIER, result, encoded)
        fail Avro::SchemaValidator::ValidationError, result if result.failure?
        result
      end

      private

      def validate_recursive(expected_schema, logical_datum, path, result, encoded = false)
        datum = if encoded
                  logical_datum
                else
                  expected_schema.type_adapter.encode(logical_datum) rescue nil
                end

        super(expected_schema, datum, path, result)
      end
    end
  end
end

Avro::SchemaValidator.singleton_class.prepend(AvroPatches::LogicalTypes::SchemaValidatorPatch)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
avro-patches-0.2.0 lib/avro-patches/logical_types/schema_validator.rb
avro-patches-0.1.0 lib/avro-patches/logical_types/schema_validator.rb
avro-patches-0.1.0.rc0 lib/avro-patches/logical_types/schema_validator.rb