Sha256: 00a83a451a9c1306d48ce43437444f12d67e03e18e2fdb77ef835d9d2a532672

Contents?: true

Size: 709 Bytes

Versions: 5

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true

require 'avromatic/model/types/abstract_type'

module Avromatic
  module Model
    module Types
      class NullType < AbstractType
        VALUE_CLASSES = [::NilClass].freeze

        def value_classes
          VALUE_CLASSES
        end

        def name
          'null'
        end

        def coerce(input)
          if input.nil?
            nil
          else
            raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}")
          end
        end

        def coercible?(input)
          input.nil?
        end

        alias_method :coerced?, :coercible?

        def serialize(_value, **)
          nil
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
avromatic-2.2.1 lib/avromatic/model/types/null_type.rb
avromatic-2.2.0 lib/avromatic/model/types/null_type.rb
avromatic-2.1.0 lib/avromatic/model/types/null_type.rb
avromatic-2.0.1 lib/avromatic/model/types/null_type.rb
avromatic-2.0.0 lib/avromatic/model/types/null_type.rb