class Avromatic::Model::Types::EnumType
Constants
- INPUT_CLASSES
- VALUE_CLASSES
Attributes
allowed_values[R]
Public Class Methods
new(allowed_values)
click to toggle source
Calls superclass method
# File lib/avromatic/model/types/enum_type.rb, line 14 def initialize(allowed_values) super() @allowed_values = allowed_values.to_set end
Public Instance Methods
coerce(input)
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 31 def coerce(input) if input.nil? input elsif coercible?(input) input.to_s else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end
coerced?(input)
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 41 def coerced?(input) input.nil? || (input.is_a?(::String) && allowed_values.include?(input)) end
coercible?(input)
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 45 def coercible?(input) input.nil? || (input.is_a?(::String) && allowed_values.include?(input)) || (input.is_a?(::Symbol) && allowed_values.include?(input.to_s)) end
input_classes()
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 27 def input_classes INPUT_CLASSES end
name()
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 19 def name "enum#{allowed_values.to_a}" end
referenced_model_classes()
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 55 def referenced_model_classes EMPTY_ARRAY end
serialize(value, _strict)
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 51 def serialize(value, _strict) value end
value_classes()
click to toggle source
# File lib/avromatic/model/types/enum_type.rb, line 23 def value_classes VALUE_CLASSES end