diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-05-30 14:22:17 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-05-30 14:22:17 +0200 |
commit | 4321cd09a5b81fee278e39564d4729784732611c (patch) | |
tree | e1b968ed5c084d0edc6eed0c755ca53aaefe9f90 /activerecord/lib/active_record/connection_adapters/postgresql | |
parent | b9eeb0339df7bd746273d680a26258df78dbd262 (diff) | |
download | rails-4321cd09a5b81fee278e39564d4729784732611c.tar.gz rails-4321cd09a5b81fee278e39564d4729784732611c.tar.bz2 rails-4321cd09a5b81fee278e39564d4729784732611c.zip |
refactor, introduce `Type#type_cast_for_schema` to cast for schema.rb
This removes the case statement in `SchemaDumper` and gives every `Type`
the possibility to control the SchemaDumper default value output.
/cc @sgrif
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb index 507c3a62b0..158468fe5b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb @@ -7,6 +7,17 @@ module ActiveRecord :cidr end + def type_cast_for_schema(value) + subnet_mask = value.instance_variable_get(:@mask_addr) + + # If the subnet mask is equal to /32, don't output it + if subnet_mask == (2**32 - 1) + "\"#{value.to_s}\"" + else + "\"#{value.to_s}/#{subnet_mask.to_s(2).count('1')}\"" + end + end + def cast_value(value) ConnectionAdapters::PostgreSQLColumn.string_to_cidr value end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb index c2262c1599..a0d8a94c74 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb @@ -24,6 +24,10 @@ module ActiveRecord value.respond_to?(:infinite?) && value.infinite? end + def type_cast_for_schema(value) + value.inspect.gsub('Infinity', '::Float::INFINITY') + end + def type_cast_single(value) infinity?(value) ? value : @subtype.type_cast(value) end |