collectiveidea/delayed_job_active_record — pull request #4 by rchekaluk (2011-12-24 23:09:41+00:00)
Title: Support transient attributes in Active Record objects

This is the 2nd of two companion pull requests (the other in delayed_job), and is dependent on the first one.

This pull request implements support for transient attributes in active_record objects. When delayed_job changed its deserialization approach to deserialize by populating objects from the database, it lost the ability to deserialize yaml containing transient attributes. It monkey patches ActiveRecord::Base to add an encode_with for serialization, and an init_with for deserialization. Transient attributes must be declared using attr_accessor-type macros; the modification determines transient attributes by examining a class's instance variables, and subtracting any that are internal to active_record or delayed_job.

This has been tested using Active Record 3.0.10 and 3.1.3 (the modification also contains support for Rails 2 but this has not been tested). This has been also been tested embedded into an app on Heroku cedar.