Sha256: 6e44e2f16cee4d5275ef4fdd1f7580a6d8bd8d9422b4892a1460b40677bac232
Contents?: true
Size: 738 Bytes
Versions: 12
Compression:
Stored size: 738 Bytes
Contents
require 'ipaddr' module DataMapper module Types class IPAddress < DataMapper::Type primitive String 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 def self.dump(value, property) return nil if value.nil? value.to_s end def self.typecast(value, property) value.kind_of?(IPAddr) ? value : load(value, property) end end # class IPAddress end # module Types end # module DataMapper
Version data entries
12 entries across 12 versions & 2 rubygems