Sha256: 72663476bf99bae964824693372c26a2d50999e64c0e561a127368f5cdbb4650

Contents?: true

Size: 1 KB

Versions: 121

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module PostgreSQL
      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

121 entries across 116 versions & 11 rubygems

Version Path
activerecord-8.0.0.beta1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
omg-activerecord-8.0.0.alpha9 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
omg-activerecord-8.0.0.alpha8 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
omg-activerecord-8.0.0.alpha7 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
omg-activerecord-8.0.0.alpha4 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
omg-activerecord-8.0.0.alpha3 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
omg-activerecord-8.0.0.alpha2 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
omg-activerecord-8.0.0.alpha1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-7.1.4 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-7.2.1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-7.2.0 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-7.2.0.rc1 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-7.2.0.beta3 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
activerecord-7.2.0.beta2 lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb