Class: Avromatic::Model::Types::FixedType
- Inherits:
-
AbstractType
- Object
- AbstractType
- Avromatic::Model::Types::FixedType
- Defined in:
- lib/avromatic/model/types/fixed_type.rb
Constant Summary collapse
- VALUE_CLASSES =
[::String].freeze
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #coerce(input) ⇒ Object
- #coercible?(input) ⇒ Boolean (also: #coerced?)
-
#initialize(size) ⇒ FixedType
constructor
A new instance of FixedType.
- #name ⇒ Object
- #referenced_model_classes ⇒ Object
- #serialize(value, _strict) ⇒ Object
- #value_classes ⇒ Object
Methods inherited from AbstractType
Constructor Details
#initialize(size) ⇒ FixedType
Returns a new instance of FixedType.
13 14 15 16 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 13 def initialize(size) super() @size = size end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
11 12 13 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 11 def size @size end |
Instance Method Details
#coerce(input) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 26 def coerce(input) if coercible?(input) input else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end |
#coercible?(input) ⇒ Boolean Also known as: coerced?
34 35 36 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 34 def coercible?(input) input.nil? || (input.is_a?(::String) && input.length == size) end |
#name ⇒ Object
18 19 20 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 18 def name "fixed(#{size})" end |
#referenced_model_classes ⇒ Object
44 45 46 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 44 def referenced_model_classes EMPTY_ARRAY end |
#serialize(value, _strict) ⇒ Object
40 41 42 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 40 def serialize(value, _strict) value end |
#value_classes ⇒ Object
22 23 24 |
# File 'lib/avromatic/model/types/fixed_type.rb', line 22 def value_classes VALUE_CLASSES end |