<commit_before>= mongoid-history

In frustration of Mongoid::Versioning, I created this plugin for tracking historical changes for any document, including embedded ones. It achieves this by storing all history tracks in a single collection that you define. (See Usage for more details) Embedded documents are referenced by storing an association path, which is an array of document_name and document_id fields starting from the top most parent document and down to the embedded document that should track history.

This plugin implements multi-user undo, which allows users to undo any history change in any order. Undoing a document also creates a new history track. This is great for auditing and preventing vandalism, but it is probably not suitable for use cases such as a wiki.

== Install

  gem install mongoid-history

== Rails 3

In your Gemfile:

  gem 'mongoid-history'

== Usage

Here is a quick example on how to use this plugin. For more details, please look at spec/integration/integration_spec.rb. It offers more detailed examples on how to use Mongoid::History.

=== Create a History Tracker

Create a new class to track histories. All histories are stored in this tracker. The name of the class can be anything you like. The only requirement is that it includes `Mongoid::History::Tracker`

  # app/models/history_tracker.rb
  class HistoryTracker
    include Mongoid::History::Tracker
  end

Now it's good to verify this is done correctly, because nothing will work without this being correctly hooked up. You can check like this in irb:

  # Assuming your history tracker is HistoryTracker
  require 'mongoid'
  require 'mongoid-history'
  require './app/models/history_tracker'
  Mongoid::History.tracker_class # Make sure it is the HistoryTracker class

=== Create Trackable classes and objects

  class Post
    include Mongoid::Document
    include Mongoid::Timestamps

    # History tracking all Post Documents
    # Note: Tracking will not work until #track_history is invoked<commit_msg>update readme to suggest setting of tracker_class_name<commit_after>= mongoid-history

In frustration of Mongoid::Versioning, I created this plugin for tracking historical changes for any document, including embedded ones. It achieves this by storing all history tracks in a single collection that you define. (See Usage for more details) Embedded documents are referenced by storing an association path, which is an array of document_name and document_id fields starting from the top most parent document and down to the embedded document that should track history.

This plugin implements multi-user undo, which allows users to undo any history change in any order. Undoing a document also creates a new history track. This is great for auditing and preventing vandalism, but it is probably not suitable for use cases such as a wiki.

== Install

  gem install mongoid-history

== Rails 3

In your Gemfile:

  gem 'mongoid-history'

== Usage

Here is a quick example on how to use this plugin. For more details, please look at spec/integration/integration_spec.rb. It offers more detailed examples on how to use Mongoid::History.

=== Create a History Tracker

Create a new class to track histories. All histories are stored in this tracker. The name of the class can be anything you like. The only requirement is that it includes `Mongoid::History::Tracker`

  # app/models/history_tracker.rb
  class HistoryTracker
    include Mongoid::History::Tracker
  end

=== Set the name of the tracker class

You should manually set the tracker class name to make sure `HistoryTracker` can be found and loaded on demand. You can skip this step if you manually require your history tracker class before using any trackables. If you don't know what I'm talking about, then you should follow the example below.

Here is an example of setting the tracker class name using a rails initializer

  # config/initializers/mongoid-history.rb
  # initializer for mongoid-history
  # assuming HistoryTracker is your tracker class
  Mongoid::History.tracker_class_name = :history_tracker


=== Create Trackable classes and objects

  class Post
    include Mongoid::Document
    include Mongoid::Timestamps

    # History tracking all Post Documents
    # Note: Tracking will not work until #track_history is invoked
{'fraction_non_alphanumeric': 0.04360937137555092, 'fraction_numerical': 0.00046392948271862676, 'mean_word_length': 4.437578814627995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1939015', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1014, 'n_words': 591}