Sha256: ca84d62806bf8c14c62005dc6147c27bc5c851a5daa0fcc523d5e01dc874c380

Contents?: true

Size: 1000 Bytes

Versions: 34

Compression:

Stored size: 1000 Bytes

Contents

# frozen_string_literal: true

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

          def type
            :point
          end

          def cast(value)
            case value
            when ::String
              if value[0] == "(" && value[-1] == ")"
                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.gsub(/\.0$/, "")
            end
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 4 rubygems

Version Path
activerecord-5.2.3.rc1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.2.1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
nullifyable-0.1.0 vendor/bundle/gems/activerecord-5.2.2/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.2 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.2.rc1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.1.1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.1.rc1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.0 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.0.rc2 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.0.rc1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.0.beta2 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-5.2.0.beta1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
ruby-on-quails-0.1.0 activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb