/mongo_mapper_acts_as_versioned

Basic MongoMapper port of technoweenie's acts_as_versioned

Primary LanguageRubyMIT LicenseMIT

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.

Usage

Basic Example

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'

Keys that do not trigger new versions

Default ignored keys are:

  • "_id"
  • "created_at"
  • "updated_at"
  • "creator_id"
  • "updater_id"
  • "version"
  • "_type"
  • "_versioned_type"
  • versioned_foreign_key

Ignoring additional keys

Simply add self.non_versioned_keys << 'new_skipped_key' somewhere in your model.

Tested with

  • MongoMapper 0.11.1
  • Ruby 1.9.2

TODO

  • Add loads more options
  • Properly document those options

Copyright

Copyright (c) 2010 Gigamo <gigamo@gmail.com>. See LICENSE for details.