diff options
Diffstat (limited to 'activerecord')
3 files changed, 11 insertions, 10 deletions
diff --git a/activerecord/activerecord.gemspec b/activerecord/activerecord.gemspec index b91940569e..e8e5f4adfe 100644 --- a/activerecord/activerecord.gemspec +++ b/activerecord/activerecord.gemspec @@ -24,5 +24,4 @@ Gem::Specification.new do |s| s.add_dependency('arel', '~> 3.0.2') s.add_dependency('active_record_deprecated_finders', '0.0.1') - s.add_dependency('netaddr', '~> 1.5.0') end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 45149e69a6..6714970103 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -3,12 +3,13 @@ require 'active_support/core_ext/object/blank' require 'active_record/connection_adapters/statement_pool' require 'active_record/connection_adapters/postgresql/oid' require 'arel/visitors/bind_visitor' -require 'netaddr' # Make sure we're using pg high enough for PGResult#values gem 'pg', '~> 0.11' require 'pg' +require 'ipaddr' + module ActiveRecord module ConnectionHandling # Establishes a connection to the database that's used by all Active Record objects @@ -84,7 +85,7 @@ module ActiveRecord if string.nil? nil elsif String === string - NetAddr::CIDR.create(string) + IPAddr.new(string) else string end @@ -92,8 +93,8 @@ module ActiveRecord end def cidr_to_string(object) - if NetAddr::CIDR === object - object.to_s + if IPAddr === object + "#{object.to_s}/#{object.instance_variable_get(:@mask_addr).to_s(2).count('1')}" else object end @@ -549,7 +550,7 @@ module ActiveRecord when 'hstore' then super(PostgreSQLColumn.hstore_to_string(value), column) else super end - when NetAddr::CIDR, NetAddr::CIDRv4, NetAddr::CIDRv6 + when IPAddr case column.sql_type when 'inet', 'cidr' then super(PostgreSQLColumn.cidr_to_string(value), column) else super @@ -593,7 +594,7 @@ module ActiveRecord when Hash return super unless 'hstore' == column.sql_type PostgreSQLColumn.hstore_to_string(value) - when NetAddr::CIDR, NetAddr::CIDRv4, NetAddr::CIDRv6 + when IPAddr return super unless ['inet','cidr'].includes? column.sql_type PostgreSQLColumn.cidr_to_string(value) else diff --git a/activerecord/test/cases/adapters/postgresql/datatype_test.rb b/activerecord/test/cases/adapters/postgresql/datatype_test.rb index cf58c3089f..34660577da 100644 --- a/activerecord/test/cases/adapters/postgresql/datatype_test.rb +++ b/activerecord/test/cases/adapters/postgresql/datatype_test.rb @@ -134,9 +134,10 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase assert_equal '-1 years -2 days', @first_time.time_interval end - def test_network_address_values - cidr_address = NetAddr::CIDR.create '192.168.0.0/24' - inet_address = NetAddr::CIDR.create '172.16.1.254' + def test_network_address_values_ipaddr + cidr_address = IPAddr.new '192.168.0.0/24' + inet_address = IPAddr.new '172.16.1.254' + assert_equal cidr_address, @first_network_address.cidr_address assert_equal inet_address, @first_network_address.inet_address assert_equal '01:23:45:67:89:0a', @first_network_address.mac_address |