class Avromatic::Model::Types::AbstractTimestampType
Constants
- INPUT_CLASSES
- VALUE_CLASSES
Public Instance Methods
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 20 def coerce(input) if input.nil? || coerced?(input) input elsif input.is_a?(::Time) || input.is_a?(::DateTime) coerce_time(input) else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 34 def coerced?(value) # ActiveSupport::TimeWithZone overrides is_a? is to make it look like a Time # even though it's not which can lead to unexpected behavior if we don't force # a coercion value.is_a?(::Time) && value.class != ActiveSupport::TimeWithZone && truncated?(value) end
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 30 def coercible?(input) input.nil? || input.is_a?(::Time) || input.is_a?(::DateTime) end
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 16 def input_classes INPUT_CLASSES end
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 41 def serialize(value, _strict) value end
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 12 def value_classes VALUE_CLASSES end
Private Instance Methods
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 51 def coerce_time(_input) raise "#{__method__} must be overridden by #{self.class.name}" end
Source
# File lib/avromatic/model/types/abstract_timestamp_type.rb, line 47 def truncated?(_value) raise "#{__method__} must be overridden by #{self.class.name}" end