Class: DataMapper::Property::Legacy::NumericIPAddr
- Inherits:
-
Integer
- Object
- Integer
- DataMapper::Property::Legacy::NumericIPAddr
- Defined in:
- lib/dm-core/property/legacy/numeric_ip_addr.rb
Instance Method Summary collapse
-
#dump(value) ⇒ Integer?
Dumps an IP Address to a numeric value.
-
#load(value) ⇒ IPAddr?
Loads a numeric IP Address.
-
#load_integer(value) ⇒ IPAddr
protected
Loads an IPv4 or IPv6 address from an integer.
-
#typecast(value) ⇒ IPAddr?
Typecasts an IP Address.
Instance Method Details
#dump(value) ⇒ Integer?
Dumps an IP Address to a numeric value.
51 52 53 |
# File 'lib/dm-core/property/legacy/numeric_ip_addr.rb', line 51 def dump(value) value.to_i unless value.nil? end |
#load(value) ⇒ IPAddr?
Loads a numeric IP Address.
19 20 21 |
# File 'lib/dm-core/property/legacy/numeric_ip_addr.rb', line 19 def load(value) load_integer(value) unless value.nil? end |
#load_integer(value) ⇒ IPAddr (protected)
Loads an IPv4 or IPv6 address from an integer.
66 67 68 69 70 71 72 |
# File 'lib/dm-core/property/legacy/numeric_ip_addr.rb', line 66 def load_integer(value) if value > 4294967295 # (2 ** 32) - 1 ::IPAddr.new(value,Socket::AF_INET6) elsif value >= 0 ::IPAddr.new(value,Socket::AF_INET) end end |
#typecast(value) ⇒ IPAddr?
Typecasts an IP Address.
32 33 34 35 36 37 38 39 40 |
# File 'lib/dm-core/property/legacy/numeric_ip_addr.rb', line 32 def typecast(value) if value.kind_of?(::IPAddr) value elsif value.kind_of?(::String) ::IPAddr.new(value) unless value.empty? elsif value.kind_of?(::Integer) load_integer(value) end end |