Sha256: 650a24064a8d9578f50892202575e5deb19b026857d495735a012ba38bb9f9e1

Contents?: true

Size: 1 KB

Versions: 66

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module CipherStashPG
      module OID # :nodoc:
        class LegacyPoint < Type::Value # :nodoc:
          include ActiveModel::Type::Helpers::Mutable

          def type
            :point
          end

          def cast(value)
            case value
            when ::String
              if value.start_with?("(") && value.end_with?(")")
                value = value[1...-1]
              end
              cast(value.split(","))
            when ::Array
              value.map { |v| Float(v) }
            else
              value
            end
          end

          def serialize(value)
            if value.is_a?(::Array)
              "(#{number_for_point(value[0])},#{number_for_point(value[1])})"
            else
              super
            end
          end

          private
            def number_for_point(number)
              number.to_s.delete_suffix(".0")
            end
        end
      end
    end
  end
end

Version data entries

66 entries across 32 versions & 1 rubygems

Version Path
activerecord-cipherstash-pg-adapter-0.8.5 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.5 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.5 lib/active_record/connection_adapters/7.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.4 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.4 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.4 lib/active_record/connection_adapters/7.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.3 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.3 lib/active_record/connection_adapters/7.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.3 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.2 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.2 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.2 lib/active_record/connection_adapters/7.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.1 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.1 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.0 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.8.0 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.7.19 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.7.19 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.7.18 lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
activerecord-cipherstash-pg-adapter-0.7.18 lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb