mongoid-history 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -6
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -4
- data/README.md +7 -30
- data/VERSION +1 -1
- data/config/mongoid.yml +8 -0
- data/lib/mongoid/history/trackable.rb +3 -3
- data/lib/mongoid/history/tracker.rb +2 -1
- data/mongoid-history.gemspec +5 -4
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/support/mongoid.rb +9 -3
- metadata +7 -6
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
gem "easy_diff"
|
4
|
-
gem "mongoid", "
|
4
|
+
gem "mongoid", "~> 3.0.4"
|
5
5
|
|
6
6
|
group :test do
|
7
|
-
gem "
|
8
|
-
gem "rspec"
|
7
|
+
gem "rspec", "~> 2.11.0"
|
9
8
|
gem "yard"
|
10
9
|
gem "bundler", ">= 1.0.0"
|
11
10
|
gem "jeweler"
|
12
|
-
gem "database_cleaner"
|
11
|
+
gem "database_cleaner", ">= 0.8.0"
|
13
12
|
end
|
data/README.md
CHANGED
@@ -3,40 +3,19 @@ mongoid-history
|
|
3
3
|
|
4
4
|
[![Build Status](https://secure.travis-ci.org/aq1018/mongoid-history.png?branch=master)](http://travis-ci.org/aq1018/mongoid-history) [![Dependency Status](https://gemnasium.com/aq1018/mongoid-history.png?travis)](https://gemnasium.com/aq1018/mongoid-history)
|
5
5
|
|
6
|
+
Mongoid-history tracks historical changes for any document, including embedded ones. It achieves this by storing all history tracks in a single collection that you define. 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.
|
6
7
|
|
7
|
-
|
8
|
+
This gem also 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 is probably not suitable for use cases such as a wiki.
|
8
9
|
|
9
|
-
|
10
|
+
Stable Release
|
11
|
+
--------------
|
10
12
|
|
11
|
-
|
12
|
-
----
|
13
|
-
|
14
|
-
**Please don't use 0.1.8 and 0.2.0.**
|
15
|
-
|
16
|
-
These versions won't work in Rails because there was an error in the sweeper that causes history tracker creation to fail. Upgrade to version 0.2.1 instead as it's able to track history on `embeds_one` documents correctly.
|
17
|
-
|
18
|
-
**Refactor in progress**
|
19
|
-
|
20
|
-
If you feel brave, you can look at the `refactor` branch and get a feel of what's coming. As I stated many times before, this gem was originally hacked up in one evening, and got patched many times by various fellow users. Thus the code has become pretty unmanagable over time. The `refactor` branch tries repay this technical debt by breaking things down into smaller class and implement better tests. Stay tuned! :D
|
21
|
-
|
22
|
-
Upgrading from mongoid-history-0.1.x to >= 0.2
|
23
|
-
------------------------------------------------
|
24
|
-
|
25
|
-
If you are upgrading from 0.1.x to version 0.2.x and have existing data, run the following code **before** you start using 0.2.x. This is due to changes in `Mongoid::History::Tracker`'s `association_chain` field.
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
Mongoid::History.tracker_class.all.each do |tracker|
|
29
|
-
tracker.association_chain[1..-1].each do |node|
|
30
|
-
node['name'] = node['name'].tableize
|
31
|
-
end
|
32
|
-
tracker.save!
|
33
|
-
end
|
34
|
-
```
|
13
|
+
You're reading the documentation the 0.3.x release that supports Mongoid 3.x. For 2.x compatible mongoid-history, please use a 0.2.x version from the [2.x-stable branch](https://github.com/aq1018/mongoid-history/tree/2.4-stable).
|
35
14
|
|
36
15
|
Install
|
37
16
|
-------
|
38
17
|
|
39
|
-
This gem supports
|
18
|
+
This gem supports Mongoid 3.x on Ruby 1.9.3 only. Add it to your `Gemfile` or run `gem install mongoid-history`.
|
40
19
|
|
41
20
|
```ruby
|
42
21
|
gem 'mongoid-history'
|
@@ -45,8 +24,6 @@ gem 'mongoid-history'
|
|
45
24
|
Usage
|
46
25
|
-----
|
47
26
|
|
48
|
-
Here is a quick example on how to use this plugin.
|
49
|
-
|
50
27
|
**Create a history tracker**
|
51
28
|
|
52
29
|
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`
|
@@ -60,7 +37,7 @@ end
|
|
60
37
|
|
61
38
|
**Set tracker class name**
|
62
39
|
|
63
|
-
|
40
|
+
Manually set the tracker class name to make sure your tracker can be found and loaded properly. You can skip this step if you manually require your tracker before using any trackables.
|
64
41
|
|
65
42
|
The following example sets the tracker class name using a Rails initializer.
|
66
43
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/config/mongoid.yml
ADDED
@@ -4,7 +4,7 @@ module Mongoid::History
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
def track_history(options={})
|
7
|
-
scope_name = self.collection_name.singularize.to_sym
|
7
|
+
scope_name = self.collection_name.to_s.singularize.to_sym
|
8
8
|
default_options = {
|
9
9
|
:on => :all,
|
10
10
|
:except => [:created_at, :updated_at],
|
@@ -34,7 +34,7 @@ module Mongoid::History
|
|
34
34
|
end
|
35
35
|
|
36
36
|
field options[:version_field].to_sym, :type => Integer
|
37
|
-
|
37
|
+
belongs_to options[:modifier_field].to_sym, :class_name => Mongoid::History.modifier_class_name
|
38
38
|
|
39
39
|
include MyInstanceMethods
|
40
40
|
extend SingletonMethods
|
@@ -246,7 +246,7 @@ module Mongoid::History
|
|
246
246
|
|
247
247
|
module SingletonMethods
|
248
248
|
def history_trackable_options
|
249
|
-
@history_trackable_options ||= Mongoid::History.trackable_class_options[self.collection_name.singularize.to_sym]
|
249
|
+
@history_trackable_options ||= Mongoid::History.trackable_class_options[self.collection_name.to_s.singularize.to_sym]
|
250
250
|
end
|
251
251
|
end
|
252
252
|
end
|
@@ -13,7 +13,7 @@ module Mongoid::History
|
|
13
13
|
field :version, :type => Integer
|
14
14
|
field :action, :type => String
|
15
15
|
field :scope, :type => String
|
16
|
-
|
16
|
+
belongs_to :modifier, :class_name => Mongoid::History.modifier_class_name
|
17
17
|
|
18
18
|
Mongoid::History.tracker_class_name = self.name.tableize.singularize.to_sym
|
19
19
|
|
@@ -95,6 +95,7 @@ private
|
|
95
95
|
def create_standalone
|
96
96
|
class_name = association_chain.first["name"]
|
97
97
|
restored = class_name.constantize.new(modified)
|
98
|
+
restored.id = modified["_id"]
|
98
99
|
restored.save!
|
99
100
|
end
|
100
101
|
|
data/mongoid-history.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mongoid-history"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Qian", "Justin Grimes"]
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"README.md",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
|
+
"config/mongoid.yml",
|
29
30
|
"lib/mongoid-history.rb",
|
30
31
|
"lib/mongoid/history.rb",
|
31
32
|
"lib/mongoid/history/sweeper.rb",
|
@@ -50,14 +51,14 @@ Gem::Specification.new do |s|
|
|
50
51
|
|
51
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
53
|
s.add_runtime_dependency(%q<easy_diff>, [">= 0"])
|
53
|
-
s.add_runtime_dependency(%q<mongoid>, ["
|
54
|
+
s.add_runtime_dependency(%q<mongoid>, ["~> 3.0.4"])
|
54
55
|
else
|
55
56
|
s.add_dependency(%q<easy_diff>, [">= 0"])
|
56
|
-
s.add_dependency(%q<mongoid>, ["
|
57
|
+
s.add_dependency(%q<mongoid>, ["~> 3.0.4"])
|
57
58
|
end
|
58
59
|
else
|
59
60
|
s.add_dependency(%q<easy_diff>, [">= 0"])
|
60
|
-
s.add_dependency(%q<mongoid>, ["
|
61
|
+
s.add_dependency(%q<mongoid>, ["~> 3.0.4"])
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
data/spec/support/mongoid.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
end
|
1
|
+
ENV["MONGOID_ENV"] = "test"
|
2
|
+
Mongoid.load!("config/mongoid.yml")
|
4
3
|
|
5
4
|
RSpec.configure do |config|
|
6
5
|
config.before :each do
|
7
6
|
Mongoid.observers = Mongoid::History::Sweeper
|
8
7
|
end
|
8
|
+
config.backtrace_clean_patterns = [
|
9
|
+
# /\/lib\d*\/ruby\//,
|
10
|
+
# /bin\//,
|
11
|
+
# /gems/,
|
12
|
+
# /spec\/spec_helper\.rb/,
|
13
|
+
/lib\/rspec\/(core|expectations|matchers|mocks)/
|
14
|
+
]
|
9
15
|
end
|
10
16
|
|
11
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-history
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -33,17 +33,17 @@ dependencies:
|
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
none: false
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ~>
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
38
|
+
version: 3.0.4
|
39
39
|
type: :runtime
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 3.0.4
|
47
47
|
description: ! "In frustration of Mongoid::Versioning, I created this plugin for tracking
|
48
48
|
historical changes for any document, including embedded ones. It achieves this by
|
49
49
|
storing all history tracks in a single collection that you define. (See Usage for
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
74
74
|
- VERSION
|
75
|
+
- config/mongoid.yml
|
75
76
|
- lib/mongoid-history.rb
|
76
77
|
- lib/mongoid/history.rb
|
77
78
|
- lib/mongoid/history/sweeper.rb
|
@@ -99,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
100
|
version: '0'
|
100
101
|
segments:
|
101
102
|
- 0
|
102
|
-
hash:
|
103
|
+
hash: 877523070155476761
|
103
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
105
|
none: false
|
105
106
|
requirements:
|