Class: Avromatic::Model::Types::DateType

Inherits:
AbstractType show all
Defined in:
lib/avromatic/model/types/date_type.rb

Constant Summary collapse

VALUE_CLASSES =
[::Date].freeze
INPUT_CLASSES =
[::Date, ::Time].freeze

Instance Method Summary collapse

Methods inherited from AbstractType

#coerced?, #coercible?

Instance Method Details

#coerce(input) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/avromatic/model/types/date_type.rb', line 24

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

#input_classesObject



16
17
18
# File 'lib/avromatic/model/types/date_type.rb', line 16

def input_classes
  INPUT_CLASSES
end

#nameObject



20
21
22
# File 'lib/avromatic/model/types/date_type.rb', line 20

def name
  'date'
end

#referenced_model_classesObject



38
39
40
# File 'lib/avromatic/model/types/date_type.rb', line 38

def referenced_model_classes
  EMPTY_ARRAY
end

#serialize(value, _strict) ⇒ Object



34
35
36
# File 'lib/avromatic/model/types/date_type.rb', line 34

def serialize(value, _strict)
  value
end

#value_classesObject



12
13
14
# File 'lib/avromatic/model/types/date_type.rb', line 12

def value_classes
  VALUE_CLASSES
end