Sha256: ab0cd9f17da15aa17f27fa430902d2d6bc4d6997054de61de3f64aefeec59889

Contents?: true

Size: 662 Bytes

Versions: 43

Compression:

Stored size: 662 Bytes

Contents

module Avromatic
  module Model
    module Attribute

      # This subclass of Virtus::Attribute is used to truncate timestamp values
      # to the supported precision.
      class AbstractTimestamp < Virtus::Attribute
        def coerce(value)
          return value if value.nil? || value_coerced?(value)

          value.is_a?(Time) ? coerce_time(value) : value
        end

        def value_coerced?(_value)
          raise "#{__method__} must be overridden by #{self.class.name}"
        end

        private

        def coerce_time(_value)
          raise "#{__method__} must be overridden by #{self.class.name}"
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
avromatic-0.10.0.rc1 lib/avromatic/model/attribute/abstract_timestamp.rb
avromatic-0.10.0.rc0 lib/avromatic/model/attribute/abstract_timestamp.rb
avromatic-0.9.0 lib/avromatic/model/attribute/abstract_timestamp.rb