diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-08-31 14:07:47 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-08-31 14:09:12 -0400 |
commit | b347156b15aea7f6229203e0cc1a58937ecb8e93 (patch) | |
tree | aef65dd98d78468ce3f3f93dac1fd15b2f3b326c /activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb | |
parent | 6236cb7e6ad8bc18af2c3dc0118708d3e456bdce (diff) | |
download | rails-b347156b15aea7f6229203e0cc1a58937ecb8e93.tar.gz rails-b347156b15aea7f6229203e0cc1a58937ecb8e93.tar.bz2 rails-b347156b15aea7f6229203e0cc1a58937ecb8e93.zip |
Remove deprecated handling of PG Points
There are some minor changes to the point type as I had forgotten that
this will affect the behavior of `t.point` in migrations and the schema
dumper so we need to handle those as well.
I'll say this again so I can convince myself to come up with a better
structure... TYPES SHOULD NOT CARE ABOUT SCHEMA DUMPING AND WE NEED TO
BETTER SEPARATE THESE.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb new file mode 100644 index 0000000000..775eecaf85 --- /dev/null +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb @@ -0,0 +1,43 @@ +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 |