Class: Avromatic::Model::Types::StringType
- Inherits:
-
Object
- Object
- Avromatic::Model::Types::StringType
- Defined in:
- lib/avromatic/model/types/string_type.rb
Constant Summary collapse
- VALUE_CLASSES =
[::String].freeze
- INPUT_CLASSES =
[::String, ::Symbol].freeze
Instance Method Summary collapse
- #coerce(input) ⇒ Object
- #coerced?(value) ⇒ Boolean
- #coercible?(input) ⇒ Boolean
- #input_classes ⇒ Object
- #name ⇒ Object
- #serialize(value) ⇒ Object
- #value_classes ⇒ Object
Instance Method Details
#coerce(input) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/avromatic/model/types/string_type.rb', line 24 def coerce(input) if input.nil? || input.is_a?(::String) input elsif input.is_a?(::Symbol) input.to_s else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end |
#coerced?(value) ⇒ Boolean
38 39 40 |
# File 'lib/avromatic/model/types/string_type.rb', line 38 def coerced?(value) value.nil? || value.is_a?(::String) end |
#coercible?(input) ⇒ Boolean
34 35 36 |
# File 'lib/avromatic/model/types/string_type.rb', line 34 def coercible?(input) input.nil? || input.is_a?(::String) || input.is_a?(::Symbol) end |
#input_classes ⇒ Object
16 17 18 |
# File 'lib/avromatic/model/types/string_type.rb', line 16 def input_classes INPUT_CLASSES end |
#name ⇒ Object
20 21 22 |
# File 'lib/avromatic/model/types/string_type.rb', line 20 def name 'string' end |
#serialize(value) ⇒ Object
42 43 44 |
# File 'lib/avromatic/model/types/string_type.rb', line 42 def serialize(value, **) value end |
#value_classes ⇒ Object
12 13 14 |
# File 'lib/avromatic/model/types/string_type.rb', line 12 def value_classes VALUE_CLASSES end |