I'm trying to use IPAddress as a custom field for a Mongoid Document by monkey patching the serialization methods to the IPAddress module and I just can't seem to get it...
class Computer
include Mongoid::Document
field :ip_address, type: IPAddress
end
module IPAddress
def mongoize
to_string
end
def self.mongoize(object)
object.to_string
end
def self.demongoize(string)
IPAddress.new string
end
def self.evolve(object)
object.to_string
end
end
Here's what I got right this second... but I've tried lots of other ways and just can't find one that works. Any help would be much appreciated!