Class: DataMapper::Types::IPAddress

Inherits:
DataMapper::Type
  • Object
show all
Defined in:
lib/dm-types/ip_address.rb

Class Method Summary collapse

Class Method Details

.dump(value, property) ⇒ Object



20
21
22
23
# File 'lib/dm-types/ip_address.rb', line 20

def self.dump(value, property)
  return nil if value.nil?
  value.to_s
end

.load(value, property) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dm-types/ip_address.rb', line 8

def self.load(value, property)
  if value.nil?
    nil
  elsif value.is_a?(String) && !value.empty?
    IPAddr.new(value)
  elsif value.is_a?(String) && value.empty?
    IPAddr.new("0.0.0.0")
  else
    raise ArgumentError.new("+value+ must be nil or a String")
  end
end

.typecast(value, property) ⇒ Object



25
26
27
# File 'lib/dm-types/ip_address.rb', line 25

def self.typecast(value, property)
  value.kind_of?(IPAddr) ? value : load(value, property)
end