Sha256: ff0f716f8af9ef68718aa868e025c426dc5e38f3b06bad3a7fa2bef83f0446c1

Contents?: true

Size: 1.03 KB

Versions: 36

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module CipherStashPG
      module OID # :nodoc:
        class DateTime < Type::DateTime # :nodoc:
          def cast_value(value)
            case value
            when "infinity" then ::Float::INFINITY
            when "-infinity" then -::Float::INFINITY
            when / BC$/
              value = value.sub(/^\d+/) { |year| format("%04d", -year.to_i + 1) }
              super(value.delete_suffix!(" BC"))
            else
              super
            end
          end

          def type_cast_for_schema(value)
            case value
            when ::Float::INFINITY then "::Float::INFINITY"
            when -::Float::INFINITY then "-::Float::INFINITY"
            else super
            end
          end

          protected
            def real_type_unless_aliased(real_type)
              ActiveRecord::ConnectionAdapters::CipherStashPGAdapter.datetime_type == real_type ? :datetime : real_type
            end
        end
      end
    end
  end
end

Version data entries

36 entries across 32 versions & 1 rubygems

Version Path
activerecord-cipherstash-pg-adapter-0.7.8 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.7 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.6 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.5 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.4 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.3 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.2 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.1 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.7.0 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.6.1 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.6.0 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.5.0 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.4.0 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.3.0 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.2.0 lib/active_record/connection_adapters/cipherstash_pg/oid/date_time.rb
activerecord-cipherstash-pg-adapter-0.1.0 lib/active_record/connection_adapters/cipherstash_pg/oid/date_time.rb