Class: Avromatic::Model::Types::DateType
- Inherits:
-
AbstractType
- Object
- AbstractType
- Avromatic::Model::Types::DateType
- Defined in:
- lib/avromatic/model/types/date_type.rb
Constant Summary collapse
- VALUE_CLASSES =
[::Date].freeze
Instance Method Summary collapse
- #coerce(input) ⇒ Object
- #coercible?(input) ⇒ Boolean (also: #coerced?)
- #name ⇒ Object
- #referenced_model_classes ⇒ Object
- #serialize(value, _strict) ⇒ Object
- #value_classes ⇒ Object
Methods inherited from AbstractType
Instance Method Details
#coerce(input) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/avromatic/model/types/date_type.rb', line 19 def coerce(input) if input.is_a?(::Time) || input.is_a?(::DateTime) ::Date.new(input.year, input.month, input.day) elsif input.nil? || input.is_a?(::Date) input else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end |
#coercible?(input) ⇒ Boolean Also known as: coerced?
29 30 31 |
# File 'lib/avromatic/model/types/date_type.rb', line 29 def coercible?(input) input.nil? || input.is_a?(::Date) || input.is_a?(::Time) end |
#name ⇒ Object
15 16 17 |
# File 'lib/avromatic/model/types/date_type.rb', line 15 def name 'date' end |
#referenced_model_classes ⇒ Object
39 40 41 |
# File 'lib/avromatic/model/types/date_type.rb', line 39 def referenced_model_classes EMPTY_ARRAY end |
#serialize(value, _strict) ⇒ Object
35 36 37 |
# File 'lib/avromatic/model/types/date_type.rb', line 35 def serialize(value, _strict) value end |
#value_classes ⇒ Object
11 12 13 |
# File 'lib/avromatic/model/types/date_type.rb', line 11 def value_classes VALUE_CLASSES end |