Class: DataMapper::Types::IPAddress

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

Constant Summary

Constants inherited from DataMapper::Type

DataMapper::Type::PROPERTY_OPTIONS, DataMapper::Type::PROPERTY_OPTION_ALIASES

Class Method Summary collapse

Methods inherited from DataMapper::Type

bind, configure, inherited, options, primitive

Class Method Details

.dump(value, property) ⇒ Object



20
21
22
23
# File 'lib/gems/dm-types-0.9.9/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/gems/dm-types-0.9.9/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/gems/dm-types-0.9.9/lib/dm-types/ip_address.rb', line 25

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