A list of libraries to work with ActiveRecord model versioning. See property for an example.
Install
$ sudo gem install versions
Code is on github
Auto
Automatically create a new record on save if should_clone? returns true.
Attachment
Lightweight file attachment handling with transactional safety (only touch the filesystem if everything went fine). This class also handles shared attachments between versions. If you change a version’s content but not the file attached to it, there will not be a new file in the filesystem. Usage example:
class Document < ActiveRecord::Base
include Versions::Multi
has_multiple :versions
include Versions::Attachment
store_attachments_in :version, :attachment_class => 'Attachment'
end
The Document model now has “file” and “file=” methods.
Multi
Hide many versions behind a single current one. For example if you want
to version the content of a Page class, you should add a ‘version_id’ in
the “pages” table to store the current version and you will need a Version
model with a “page_id” to link back:
class Version < ActiveRecord::Base
include Versions::Auto
end
class Page < ActiveRecord::Base
include Versions::Multi
has_multiple :versions
end
Property integration
You can easily use the Versions gem to version your properties. See better dynamic attributes for an example.
Testing Gotcha
If you are testing your application with AfterCommit, you should note that the ‘after_commit’ code will NEVER BE EXECUTED if you have enabled transactional fixtures. You can fix this by disabling transactional fixtures in the tests where you need the after_commit code to execute (save file for example).
class DocumentTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
# ...
end