I have a custom class that I'm using as the value of a serialized field and, because I want to continue to develop said class, it gets reloaded with every request in development.
However, when I try to fetch an object from the database and access the serialized field, instead of getting an instance of CustomClass back, I get an instance of YAML::Object. It seems that the YAML deserializer is checking to see if CustomClass exists and if it doesn't is falls back to making a YAML::Object rather than triggering Rails' autoload magic. I'm working around it by doing:
class CustomClass
def self.force_load
end
end
class MyModel < ActiveRecord::Base
serialize :some_attr
def some_attr
CustomClass.force_reload
self[:some_attr] ||= CustomClass.new
end
end
But it's not exactly pretty. I don't want to go using composed_of because my custom class doesn't really make sense as a value object. It seems to me that YAML needs patching to force Rails to try and load the appropriate library before giving up and making a YAML::Object.