aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
diff options
context:
space:
mode:
authorDan Seaver <git@danseaver.com>2012-05-07 09:25:36 -0400
committerDan Seaver <git@danseaver.com>2012-05-07 09:25:36 -0400
commitc334175f0a83303c70cc272f7965284c79698dec (patch)
treecfb95093dfcb20df4cd3a1ce17fa0c3a04654bad /activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
parentf7b8fbd4b12e07d94b2fbd23b07e8dd9c3f0e702 (diff)
downloadrails-c334175f0a83303c70cc272f7965284c79698dec.tar.gz
rails-c334175f0a83303c70cc272f7965284c79698dec.tar.bz2
rails-c334175f0a83303c70cc272f7965284c79698dec.zip
Converts inet and cidr columns to NetAddr::CIDR
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
index c82afc232c..df3d5e4657 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -137,6 +137,14 @@ module ActiveRecord
end
end
+ class Cidr < Type
+ def type_cast(value)
+ return if value.nil?
+
+ ConnectionAdapters::PostgreSQLColumn.string_to_cidr value
+ end
+ end
+
class TypeMap
def initialize
@mapping = {}
@@ -212,11 +220,9 @@ module ActiveRecord
# FIXME: why are we keeping these types as strings?
alias_type 'tsvector', 'text'
alias_type 'interval', 'text'
- alias_type 'cidr', 'text'
- alias_type 'inet', 'text'
- alias_type 'macaddr', 'text'
alias_type 'bit', 'text'
alias_type 'varbit', 'text'
+ alias_type 'macaddr', 'text'
# FIXME: I don't think this is correct. We should probably be returning a parsed date,
# but the tests pass with a string returned.
@@ -237,6 +243,9 @@ module ActiveRecord
register_type 'polygon', OID::Identity.new
register_type 'circle', OID::Identity.new
register_type 'hstore', OID::Hstore.new
+
+ register_type 'cidr', OID::Cidr.new
+ alias_type 'inet', 'cidr'
end
end
end