Sha256: 2bfdb0d893e08511028809e8271f0f9153b0b1e6c7562c153e549dcc15b35efc

Contents?: true

Size: 417 Bytes

Versions: 2

Compression:

Stored size: 417 Bytes

Contents

require 'active_record/type'
module LocalDateTimeAttributes
  class LocalDateTimeType < ActiveRecord::Type::DateTime
    def cast(value)
      if value.instance_of? LocalDateTime
        return value
      elsif !value.nil?
        LocalDateTime.new(value)
      end
    end

    def serialize(value)
      value.try(:__getobj__)
    end

    def deserialize(value)
      cast(value).try(:to_local)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
local_date_time_attributes-0.1.2 lib/local_date_time_attributes/local_date_time_type.rb
local_date_time_attributes-0.1.1 lib/local_date_time_attributes/local_date_time_type.rb