Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr
- Inherits:
-
Type::Value
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr
- Defined in:
- lib/active_record/connection_adapters/postgresql/oid/cidr.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
- #cast_value(value) ⇒ Object
-
#changed?(old_value, new_value, _new_value_before_type_cast) ⇒ Boolean
TODO: Remove when IPAddr#== compares IPAddr#prefix.
- #serialize(value) ⇒ Object
- #type ⇒ Object
- #type_cast_for_schema(value) ⇒ Object
Instance Method Details
#cast_value(value) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_record/connection_adapters/postgresql/oid/cidr.rb', line 37 def cast_value(value) if value.nil? nil elsif String === value begin IPAddr.new(value) rescue ArgumentError nil end else value end end |
#changed?(old_value, new_value, _new_value_before_type_cast) ⇒ Boolean
TODO: Remove when IPAddr#== compares IPAddr#prefix. See github.com/ruby/ipaddr/issues/21
33 34 35 |
# File 'lib/active_record/connection_adapters/postgresql/oid/cidr.rb', line 33 def changed?(old_value, new_value, _new_value_before_type_cast) !old_value.eql?(new_value) || !old_value.nil? && old_value.prefix != new_value.prefix end |
#serialize(value) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/active_record/connection_adapters/postgresql/oid/cidr.rb', line 23 def serialize(value) if IPAddr === value "#{value}/#{value.prefix}" else value end end |
#type ⇒ Object
10 11 12 |
# File 'lib/active_record/connection_adapters/postgresql/oid/cidr.rb', line 10 def type :cidr end |
#type_cast_for_schema(value) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/active_record/connection_adapters/postgresql/oid/cidr.rb', line 14 def type_cast_for_schema(value) # If the subnet mask is equal to /32, don't output it if value.prefix == 32 "\"#{value}\"" else "\"#{value}/#{value.prefix}\"" end end |