ActsAsVersioned for MongoMapper
Basic MongoMapper port of technoweenie's acts_as_versioned. Stores changed attributes in a Hash key inside an Embedded Document instead of copying all keys from the original model.
class Page
include MongoMapper::Document
plugin MongoMapper::Acts::Versioned
key :title, String
end
page = Page.create(:title => 'title')
page.version # => 1
page.versions.size # => 1
page.title = 'new title'
page.save
page = page.reload
page.version # => 2
page.versions.size # => 2
page.title # => 'new title'
page.revert_to!(1)
page = page.reload
page.version # => 1
page.versions.size # => 2
page.title # => 'title'
Default ignored keys are:
- "_id"
- "created_at"
- "updated_at"
- "creator_id"
- "updater_id"
- "version"
- "_type"
- "_versioned_type"
- versioned_foreign_key
Simply add self.non_versioned_keys << 'new_skipped_key'
somewhere in your model.
- MongoMapper 0.11.1
- Ruby 1.9.2
- Add loads more options
- Properly document those options
Copyright (c) 2010 Gigamo <gigamo@gmail.com>. See LICENSE for details.