From 314d5579ab63ed9606d25a59cb4010be85fb3b17 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sun, 29 Jun 2014 15:44:41 -0600 Subject: Use the type object when sending point columns to the DB --- .../lib/active_record/connection_adapters/postgresql/cast.rb | 8 -------- .../connection_adapters/postgresql/oid/point.rb | 8 +++++++- .../active_record/connection_adapters/postgresql/quoting.rb | 12 ++---------- 3 files changed, 9 insertions(+), 19 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb index b0a161ff32..95fc461bae 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb @@ -2,14 +2,6 @@ module ActiveRecord module ConnectionAdapters module PostgreSQL module Cast # :nodoc: - def point_to_string(point) # :nodoc: - "(#{number_for_point(point[0])},#{number_for_point(point[1])})" - end - - def number_for_point(number) - number.to_s.gsub(/\.0$/, '') - end - def hstore_to_string(object, array_member = false) # :nodoc: if Hash === object string = object.map { |k, v| "#{escape_hstore(k)}=>#{escape_hstore(v)}" }.join(', ') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb index 9b6494867f..bac8b01d6b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb @@ -25,11 +25,17 @@ module ActiveRecord def type_cast_for_database(value) if value.is_a?(::Array) - PostgreSQLColumn.point_to_string(value) + "(#{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 diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 2818633495..07171a75d5 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -28,11 +28,7 @@ module ActiveRecord super end when Array - case sql_type - when 'point' then super(PostgreSQLColumn.point_to_string(value)) - else - super(value, array_column(column)) - end + super(value, array_column(column)) when Hash case sql_type when 'hstore' then super(PostgreSQLColumn.hstore_to_string(value), column) @@ -88,11 +84,7 @@ module ActiveRecord super(value, column) end when Array - case column.sql_type - when 'point' then PostgreSQLColumn.point_to_string(value) - else - super(value, array_column(column)) - end + super(value, array_column(column)) when Hash case column.sql_type when 'hstore' then PostgreSQLColumn.hstore_to_string(value, array_member) -- cgit v1.2.3