Sha256: 2df1de520041ffc28a83d6261af7b7c508e9b1121be843425cfb5dfefaf04735

Contents?: true

Size: 402 Bytes

Versions: 1

Compression:

Stored size: 402 Bytes

Contents

require 'active_record/type'
module LocalDateTimeAttributes
  class LocalDateTimeType < ActiveRecord::Type::DateTime
    def cast(value)
      return LocalDateTime.new(value) if value.acts_like?(:time) && !value.is_a?(LocalDateTime)
      super(value)
    end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
local_date_time_attributes-0.1.3 lib/local_date_time_attributes/local_date_time_type.rb