aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-17 19:55:59 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-17 19:55:59 -0600
commit455c692b047ad1af1670b5377a1c4313ad0d1228 (patch)
tree4990edf4a0f2dbd17ecebd4efec8b8180803a132 /activerecord/lib/active_record
parent3999f9cf0f16585ecd0e8bcd3bc482b46779e8cb (diff)
downloadrails-455c692b047ad1af1670b5377a1c4313ad0d1228.tar.gz
rails-455c692b047ad1af1670b5377a1c4313ad0d1228.tar.bz2
rails-455c692b047ad1af1670b5377a1c4313ad0d1228.zip
Detect in-place changes on point types
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/cast.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb17
2 files changed, 20 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
index acc4cdc9e8..a865c5c310 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
@@ -3,7 +3,11 @@ module ActiveRecord
module PostgreSQL
module Cast # :nodoc:
def point_to_string(point) # :nodoc:
- "(#{point[0]},#{point[1]})"
+ "(#{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:
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 9007bfb178..86277c5542 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb
@@ -3,20 +3,33 @@ module ActiveRecord
module PostgreSQL
module OID # :nodoc:
class Point < Type::Value
+ include Type::Mutable
+
def type
:point
end
def type_cast(value)
- if ::String === value
+ case value
+ when ::String
if value[0] == '(' && value[-1] == ')'
value = value[1...-1]
end
- value.split(',').map{ |v| Float(v) }
+ type_cast(value.split(','))
+ when ::Array
+ value.map { |v| Float(v) }
else
value
end
end
+
+ def type_cast_for_database(value)
+ if value.is_a?(::Array)
+ PostgreSQLColumn.point_to_string(value)
+ else
+ super
+ end
+ end
end
end
end