Class: DataMapper::Property::IPAddress

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

Instance Method Summary collapse

Instance Method Details

#dump(value) ⇒ Object



32
33
34
# File 'lib/dm-types/ip_address.rb', line 32

def dump(value)
  value.to_s unless value.nil?
end

#load(value) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dm-types/ip_address.rb', line 18

def load(value)
  if value.nil?
    nil
  elsif value.is_a?(::String)
    unless value.empty?
      IPAddr.new(value)
    else
      IPAddr.new("0.0.0.0")
    end
  else
    raise ArgumentError.new("+value+ must be nil or a String")
  end
end

#primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/dm-types/ip_address.rb', line 10

def primitive?(value)
  value.kind_of?(IPAddr)
end

#typecast_to_primitive(value) ⇒ Object



36
37
38
# File 'lib/dm-types/ip_address.rb', line 36

def typecast_to_primitive(value)
  load(value)
end

#valid?(value, negated = false) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dm-types/ip_address.rb', line 14

def valid?(value, negated = false)
  super || dump(value).kind_of?(::String)
end