Sha256: 9225992fb3190fc8e94ed4352319c6cbf9df61b122923274b0e604942ca2a396
Contents?: true
Size: 943 Bytes
Versions: 3
Compression:
Stored size: 943 Bytes
Contents
# frozen_string_literal: true require 'avromatic/model/types/abstract_type' module Avromatic module Model module Types class FixedType < AbstractType VALUE_CLASSES = [::String].freeze attr_reader :size def initialize(size) @size = size end def name "fixed(#{size})" end def value_classes VALUE_CLASSES end def coerce(input) if coercible?(input) input else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end def coercible?(input) input.nil? || (input.is_a?(::String) && input.length == size) end alias_method :coerced?, :coercible? def serialize(value, **) value 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/fixed_type.rb |
avromatic-2.2.3 | lib/avromatic/model/types/fixed_type.rb |
avromatic-2.2.2 | lib/avromatic/model/types/fixed_type.rb |