Module: IPAddressSerializer
- Defined in:
- lib/ip_address_serializer.rb
Class Method Summary collapse
-
.dump(value) ⇒ String
Save the value, which converts either a String, or an IP Object to the String representation for storage.
-
.load(value) ⇒ IP
Load the value and return the IP Object.
Class Method Details
.dump(value) ⇒ String
Save the value, which converts either a String, or an IP Object to the String representation for storage
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ip_address_serializer.rb', line 23 def self.dump(value) if value.nil? return nil end if value.is_a?(String) ip = IP.new(value) elsif (value.is_a?(IP) || value.is_a?(IP::V4) || value.is_a?(IP::V6)) ip = value end return [ip.proto, ip.to_hex, ip.pfxlen].join(DELIMITER) end |