Sha256: ff21bef5e9ca7aa782d370f9aead5c0724feed6d482c12930b7dbc34bec766fe

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 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

        def referenced_model_classes
          EMPTY_ARRAY
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
avromatic-2.2.4 lib/avromatic/model/types/null_type.rb
avromatic-2.2.3 lib/avromatic/model/types/null_type.rb
avromatic-2.2.2 lib/avromatic/model/types/null_type.rb