Class: SQLiteTypes::IpAddress
- Inherits:
-
ActiveRecord::Type::String
- Object
- ActiveRecord::Type::String
- SQLiteTypes::IpAddress
- Defined in:
- lib/sqlite_types/ip_address.rb
Instance Method Summary collapse
Instance Method Details
#serialize(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sqlite_types/ip_address.rb', line 5 def serialize(value) return if value.nil? case value when ::IPAddr "#{value}/#{value.prefix}" when ::String ip_addr = ::IPAddr.new(value) "#{ip_addr}/#{ip_addr.prefix}" else raise ArgumentError, "Invalid IP address: #{value}" end end |