mongoid-history 0.4.7 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +34 -21
- data/.travis.yml +2 -0
- data/CHANGELOG.md +65 -58
- data/Gemfile +3 -1
- data/README.md +27 -8
- data/Rakefile +0 -1
- data/lib/mongoid/history.rb +1 -2
- data/lib/mongoid/history/trackable.rb +30 -14
- data/lib/mongoid/history/tracker.rb +4 -4
- data/lib/mongoid/history/version.rb +1 -1
- data/mongoid-history.gemspec +2 -1
- data/spec/integration/embedded_in_polymorphic_spec.rb +21 -21
- data/spec/integration/integration_spec.rb +37 -17
- data/spec/integration/multi_relation_spec.rb +1 -1
- data/spec/integration/nested_embedded_documents_spec.rb +5 -5
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +6 -6
- data/spec/spec_helper.rb +3 -5
- data/spec/unit/trackable_spec.rb +50 -4
- metadata +46 -33
- data/lib/mongoid/history/mongoid.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 200d89256cdc175333764f52ff8e87d9e15c5050
|
4
|
+
data.tar.gz: 0c16bfb17523fb50f65af6b3576026d7bddaa1ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c56ee00ab7c9f6aacb8fa8e0816a4729b2f17c7b33abb6ccd95783d9d5e331182a2cf7707579e4dcd2868f48766777570b35a6497e54be37a34351c86e3963e
|
7
|
+
data.tar.gz: 5317fa4ee38a6b554dc94d85571a6e80cf6eb2a16fd57b8cfc7ca366820b57947cdd353c2cf8ad7091086953bb7945cb925785cd6a1d78bce21512a208114384
|
data/.rubocop_todo.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
#
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2015-09-17 17:43:47 -0400 using RuboCop version 0.34.1.
|
3
4
|
# The point is for the user to remove these configuration records
|
4
5
|
# one by one as the offenses are removed from the code base.
|
5
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -7,11 +8,8 @@
|
|
7
8
|
|
8
9
|
# Offense count: 3
|
9
10
|
Lint/HandleExceptions:
|
10
|
-
|
11
|
-
|
12
|
-
# Offense count: 27
|
13
|
-
Lint/Void:
|
14
|
-
Enabled: false
|
11
|
+
Exclude:
|
12
|
+
- 'spec/unit/trackable_spec.rb'
|
15
13
|
|
16
14
|
# Offense count: 12
|
17
15
|
Metrics/AbcSize:
|
@@ -21,7 +19,7 @@ Metrics/AbcSize:
|
|
21
19
|
Metrics/CyclomaticComplexity:
|
22
20
|
Max: 10
|
23
21
|
|
24
|
-
# Offense count:
|
22
|
+
# Offense count: 199
|
25
23
|
# Configuration parameters: AllowURI, URISchemes.
|
26
24
|
Metrics/LineLength:
|
27
25
|
Max: 688
|
@@ -31,31 +29,46 @@ Metrics/LineLength:
|
|
31
29
|
Metrics/MethodLength:
|
32
30
|
Max: 32
|
33
31
|
|
32
|
+
# Offense count: 2
|
33
|
+
# Configuration parameters: CountComments.
|
34
|
+
Metrics/ModuleLength:
|
35
|
+
Max: 168
|
36
|
+
|
34
37
|
# Offense count: 4
|
35
38
|
Metrics/PerceivedComplexity:
|
36
39
|
Max: 12
|
37
40
|
|
38
|
-
# Offense count:
|
41
|
+
# Offense count: 44
|
39
42
|
Style/Documentation:
|
40
|
-
|
43
|
+
Exclude:
|
44
|
+
- 'lib/mongoid/history.rb'
|
45
|
+
- 'lib/mongoid/history/trackable.rb'
|
46
|
+
- 'lib/mongoid/history/tracker.rb'
|
47
|
+
- 'lib/mongoid/history/version.rb'
|
48
|
+
- 'spec/integration/embedded_in_polymorphic_spec.rb'
|
49
|
+
- 'spec/integration/integration_spec.rb'
|
50
|
+
- 'spec/integration/multi_relation_spec.rb'
|
51
|
+
- 'spec/integration/nested_embedded_documents_spec.rb'
|
52
|
+
- 'spec/integration/nested_embedded_polymorphic_documents_spec.rb'
|
53
|
+
- 'spec/integration/subclasses_spec.rb'
|
54
|
+
- 'spec/support/mongoid_history.rb'
|
55
|
+
- 'spec/unit/trackable_spec.rb'
|
56
|
+
- 'spec/unit/tracker_spec.rb'
|
41
57
|
|
42
58
|
# Offense count: 6
|
43
59
|
Style/EachWithObject:
|
44
|
-
|
60
|
+
Exclude:
|
61
|
+
- 'lib/mongoid/history/trackable.rb'
|
62
|
+
- 'lib/mongoid/history/tracker.rb'
|
45
63
|
|
46
64
|
# Offense count: 1
|
47
65
|
# Configuration parameters: Exclude.
|
48
66
|
Style/FileName:
|
49
|
-
|
50
|
-
|
51
|
-
# Offense count: 1
|
52
|
-
Style/Lambda:
|
53
|
-
Enabled: false
|
67
|
+
Exclude:
|
68
|
+
- 'lib/mongoid-history.rb'
|
54
69
|
|
55
70
|
# Offense count: 3
|
56
71
|
Style/MultilineBlockChain:
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
Style/RegexpLiteral:
|
61
|
-
MaxSlashes: 0
|
72
|
+
Exclude:
|
73
|
+
- 'lib/mongoid/history/trackable.rb'
|
74
|
+
- 'lib/mongoid/history/tracker.rb'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,36 +1,43 @@
|
|
1
|
-
0.
|
2
|
-
|
1
|
+
0.5.0 (2015/09/18)
|
2
|
+
------------------
|
3
3
|
|
4
|
-
* [#
|
4
|
+
* [#143](https://github.com/aq1018/mongoid-history/pull/143): Added support for Mongoid 5 - [@dblock](https://github.com/dblock).
|
5
|
+
* [#133](https://github.com/aq1018/mongoid-history/pull/133): Added dynamic attributes tracking (Mongoid::Attributes::Dynamic): [@minisai](https://github.com/minisai).
|
6
|
+
* [#142](https://github.com/aq1018/mongoid-history/pull/142): Allow non-database fields to be specified in conjunction with a custom changes method - [@kayakyakr](https://github.com/kayakyakr).
|
5
7
|
|
6
|
-
0.4.
|
7
|
-
|
8
|
+
0.4.7 (2015/04/06)
|
9
|
+
------------------
|
8
10
|
|
9
|
-
* [#
|
10
|
-
* [#127](https://github.com/aq1018/mongoid-history/pull/127) - Fix gem naming per [rubygems](http://guides.rubygems.org/name-your-gem/) specs, now you can `require 'mongoid/history'` - [@nofxx](https://github.com/nofxx).
|
11
|
-
* [#129](https://github.com/aq1018/mongoid-history/pull/129) - Support multiple levels of embedded polimorphic documents - [@BrunoChauvet](https://github.com/BrunoChauvet).
|
12
|
-
* [#123](https://github.com/aq1018/mongoid-history/pull/123): Use a method compatible with mongoid-observers to determinine the version of Mongoid - [@zeitnot](https://github.com/zeitnot).
|
11
|
+
* [#124](https://github.com/aq1018/mongoid-history/pull/124): You can require both `mongoid-history` and `mongoid/history` - [@dblock](https://github.com/dblock).
|
13
12
|
|
14
|
-
0.4.
|
15
|
-
|
13
|
+
0.4.5 (2015/02/09)
|
14
|
+
------------------
|
16
15
|
|
17
|
-
* [#
|
16
|
+
* [#131](https://github.com/aq1018/mongoid-history/pull/131): Added `undo` method, that helps to get specific version of an object without saving changes - [@alexkravets](https://github.com/alexkravets).
|
17
|
+
* [#127](https://github.com/aq1018/mongoid-history/pull/127): Fixed gem naming per [rubygems](http://guides.rubygems.org/name-your-gem/) specs, now you can `require 'mongoid/history'` - [@nofxx](https://github.com/nofxx).
|
18
|
+
* [#129](https://github.com/aq1018/mongoid-history/pull/129): Support multiple levels of embedded polimorphic documents - [@BrunoChauvet](https://github.com/BrunoChauvet).
|
19
|
+
* [#123](https://github.com/aq1018/mongoid-history/pull/123): Used a method compatible with mongoid-observers to determinine the version of Mongoid - [@zeitnot](https://github.com/zeitnot).
|
18
20
|
|
19
|
-
0.4.
|
21
|
+
0.4.4 (2014/7/29)
|
20
22
|
-----------------
|
21
23
|
|
22
|
-
* [#
|
24
|
+
* [#111](https://github.com/aq1018/mongoid-history/pull/111): Fixed compatibility of `undo!` and `redo!` methods with Rails 3.x - [@mrjlynch](https://github.com/mrjlynch).
|
23
25
|
|
24
|
-
0.4.
|
25
|
-
|
26
|
+
0.4.3 (2014/07/10)
|
27
|
+
------------------
|
26
28
|
|
27
|
-
* [#
|
28
|
-
* [#106](https://github.com/aq1018/mongoid-history/pull/106) - Enabled specifying an array of relationships in `scope` - [@adbeelitamar](https://github.com/adbeelitamar).
|
29
|
-
* [#83](https://github.com/aq1018/mongoid-history/pull/83) - Added support for Mongoid 4.x, which removed `attr_accessible` in favor of protected attributes - [@dblock](https://github.com/dblock).
|
30
|
-
* [#103](https://github.com/aq1018/mongoid-history/pull/103) - Fixed compatibility with models using `default_scope` - [@mrjlynch](https://github.com/mrjlynch).
|
29
|
+
* [#110](https://github.com/aq1018/mongoid-history/pull/110): Fixed scope reference on history tracks criteria - [@adbeelitamar](https://github.com/adbeelitamar).
|
31
30
|
|
32
|
-
0.4.
|
33
|
-
|
31
|
+
0.4.2 (2014/07/01)
|
32
|
+
------------------
|
33
|
+
|
34
|
+
* [#106](https://github.com/aq1018/mongoid-history/pull/106): Added support for polymorphic relationship `scope` - [@adbeelitamar](https://github.com/adbeelitamar).
|
35
|
+
* [#106](https://github.com/aq1018/mongoid-history/pull/106): Enabled specifying an array of relationships in `scope` - [@adbeelitamar](https://github.com/adbeelitamar).
|
36
|
+
* [#83](https://github.com/aq1018/mongoid-history/pull/83): Added support for Mongoid 4.x, which removed `attr_accessible` in favor of protected attributes - [@dblock](https://github.com/dblock).
|
37
|
+
* [#103](https://github.com/aq1018/mongoid-history/pull/103): Fixed compatibility with models using `default_scope` - [@mrjlynch](https://github.com/mrjlynch).
|
38
|
+
|
39
|
+
0.4.1 (2014/01/11)
|
40
|
+
------------------
|
34
41
|
|
35
42
|
* Fixed compatibility with Mongoid 4.x - [@dblock](https://github.com/dblock).
|
36
43
|
* `Mongoid::History::Sweeper` has been removed, in accorance with Mongoid 4.x (see [#3108](https://github.com/mongoid/mongoid/issues/3108)) and Rails 4.x observer deprecation - [@dblock](https://github.com/dblock).
|
@@ -41,79 +48,79 @@
|
|
41
48
|
* Replace Jeweler with Gem-Release - [@johnnyshields](https://github.com/johnnyshields).
|
42
49
|
* Track version as a Ruby file - [@johnnyshields](https://github.com/johnnyshields).
|
43
50
|
|
44
|
-
0.4.0 (
|
45
|
-
|
51
|
+
0.4.0 (2013/06/12)
|
52
|
+
------------------
|
46
53
|
|
47
|
-
*
|
48
|
-
*
|
49
|
-
* [API Change] The `:destroy` action now stores trackers in the format `original=value, modified=nil` (previously it was the reverse)
|
54
|
+
* Added `Mongoid::History.disable` and `Mongoid::History.enabled?` methods for global tracking disablement - [@johnnyshields](https://github.com/johnnyshields).
|
55
|
+
* Added `:changes_method` that optionally overrides which method to call to collect changes - [@joelnordel](https://github.com/joelnordell).
|
56
|
+
* [API Change] The `:destroy` action now stores trackers in the format `original=value, modified=nil` (previously it was the reverse): [@johnnyshields](https://github.com/johnnyshields).
|
50
57
|
* Support for polymorphic embedded classes - [@tstepp](https://github.com/tstepp).
|
51
58
|
* Support for Mongoid field aliases, e.g. `field :n, as: :name` - [@johnnyshields](https://github.com/johnnyshields).
|
52
59
|
* Support for Mongoid embedded aliases, e.g. `embeds_many :comments, store_as: :coms` - [@johnnyshields](https://github.com/johnnyshields).
|
53
|
-
*
|
60
|
+
* Added `#tracked_changes` and `#tracked_edits` methods to `Tracker` class for nicer change summaries - [@johnnyshields](https://github.com/johnnyshields) and [@tstepp](https://github.com/tstepp).
|
54
61
|
* Refactored and exposed `#trackable_parent_class` in `Tracker`, which returns the class of the trackable regardless of whether the trackable itself has been destroyed - [@johnnyshields](https://github.com/johnnyshields).
|
55
|
-
*
|
56
|
-
*
|
62
|
+
* Added class-level `#tracked_field?` and `#tracked_fields` methods; refactor logic to determine whether a field is tracked - [@johnnyshields](https://github.com/johnnyshields).
|
63
|
+
* Fixed bug in Trackable#track_update where `return` condition at beginning of method caused a short-circuit where memoization would not be cleared properly. - [@johnnyshields](https://github.com/johnnyshields).
|
57
64
|
* Tests: Added spec for nested embedded documents - [@matekb](https://github.com/matekb).
|
58
65
|
* Tests: Test run time cut in half (~2.5s versus ~5s) by using `#let` helper and removing class initialization before each test - [@johnnyshields](https://github.com/johnnyshields).
|
59
66
|
* Tests: Remove `database_cleaner` gem in favor of `Mongoid.purge!` - [@johnnyshields](https://github.com/johnnyshields).
|
60
67
|
* Tests: Remove dependency on non-committed file `mongoid.yml` and hardcode collection to `mongoid_history_test` - [@johnnyshields](https://github.com/johnnyshields).
|
61
68
|
|
62
|
-
0.3.3 (
|
63
|
-
|
69
|
+
0.3.3 (2013/04/01)
|
70
|
+
------------------
|
64
71
|
|
65
|
-
* [#42](https://github.com/aq1018/mongoid-history/issues/42) Fix: corrected creation of association chain when using nested embedded documents - [@matekb](https://github.com/matekb).
|
66
|
-
* [#56](https://github.com/aq1018/mongoid-history/issues/56) Fix: now possible to undo setting (creating) attributes that was previously unset - [@matekb](https://github.com/matekb).
|
67
|
-
* [#49](https://github.com/aq1018/mongoid-history/issues/49) Fix: now correctly undo/redo localized fields - [@edejong](https://github.com/edejong).
|
72
|
+
* [#42](https://github.com/aq1018/mongoid-history/issues/42): Fix: corrected creation of association chain when using nested embedded documents - [@matekb](https://github.com/matekb).
|
73
|
+
* [#56](https://github.com/aq1018/mongoid-history/issues/56): Fix: now possible to undo setting (creating) attributes that was previously unset - [@matekb](https://github.com/matekb).
|
74
|
+
* [#49](https://github.com/aq1018/mongoid-history/issues/49): Fix: now correctly undo/redo localized fields - [@edejong](https://github.com/edejong).
|
68
75
|
|
69
76
|
|
70
|
-
0.3.2 (
|
71
|
-
|
77
|
+
0.3.2 (2013/01/24)
|
78
|
+
------------------
|
72
79
|
|
73
|
-
* [#54](https://github.com/aq1018/mongoid-history/pull/54)
|
74
|
-
* [#11](https://github.com/aq1018/mongoid-history/issues/11) Added `:modifier_field_inverse_of` on `track_history` that defines the `:inverse_of` relationship of the modifier class - [@matekb](https://github.com/matekb), [@dblock](https://github.com/dblock).
|
80
|
+
* [#54](https://github.com/aq1018/mongoid-history/pull/54): Used an index instead of the `$elemMatch` selector in `history_tracks` - [@vecio](https://github.com/vecio).
|
81
|
+
* [#11](https://github.com/aq1018/mongoid-history/issues/11): Added `:modifier_field_inverse_of` on `track_history` that defines the `:inverse_of` relationship of the modifier class - [@matekb](https://github.com/matekb), [@dblock](https://github.com/dblock).
|
75
82
|
|
76
|
-
0.3.1 (11/16
|
83
|
+
0.3.1 (2012/11/16)
|
77
84
|
------------------
|
78
85
|
|
79
|
-
* [#45](https://github.com/aq1018/mongoid-history/pull/45) Fix: intermittent hash ordering issue with `history_tracks` - [@getaroom](https://github.com/getaroom).
|
80
|
-
* [#50](https://github.com/aq1018/mongoid-history/pull/50) Fix: tracking of array changes, undo and redo of field changes on non-embedded objects - [@dblock](https://github.com/dblock).
|
86
|
+
* [#45](https://github.com/aq1018/mongoid-history/pull/45): Fix: intermittent hash ordering issue with `history_tracks` - [@getaroom](https://github.com/getaroom).
|
87
|
+
* [#50](https://github.com/aq1018/mongoid-history/pull/50): Fix: tracking of array changes, undo and redo of field changes on non-embedded objects - [@dblock](https://github.com/dblock).
|
81
88
|
|
82
|
-
0.3.0 (
|
83
|
-
|
89
|
+
0.3.0 (2012/08/21)
|
90
|
+
------------------
|
84
91
|
|
85
|
-
* [#41](https://github.com/aq1018/mongoid-history/pull/41) Mongoid 3.x support - [@zambot](https://github.com/zambot).
|
92
|
+
* [#41](https://github.com/aq1018/mongoid-history/pull/41): Mongoid 3.x support - [@zambot](https://github.com/zambot).
|
86
93
|
|
87
|
-
0.2.4 (
|
88
|
-
|
94
|
+
0.2.4 (2012/08/21)
|
95
|
+
------------------
|
89
96
|
|
90
|
-
* [#38](https://github.com/aq1018/mongoid-history/pull/38) Fix: allow sub-models to be tracked by using `collection_name` as the scope - [@acant](https://github.com/acant).
|
91
|
-
* [#35](https://github.com/aq1018/mongoid-history/pull/35) Fix: sweeper references record of change, not the record changed - [@dblock](https://github.com/dblock).
|
97
|
+
* [#38](https://github.com/aq1018/mongoid-history/pull/38): Fix: allow sub-models to be tracked by using `collection_name` as the scope - [@acant](https://github.com/acant).
|
98
|
+
* [#35](https://github.com/aq1018/mongoid-history/pull/35): Fix: sweeper references record of change, not the record changed - [@dblock](https://github.com/dblock).
|
92
99
|
|
93
|
-
0.2.3 (
|
94
|
-
|
100
|
+
0.2.3 (2012/04/20)
|
101
|
+
------------------
|
95
102
|
|
96
103
|
* [#23](https://github.com/aq1018/mongoid-history/pull/34): Updated `Trackable::association_hash` to write through parent - [@tcopple](https://github.com/tcopple).
|
97
104
|
* Fix: `Trackable::association_hash` nil meta value call - [@tcopple](https://github.com/tcopple).
|
98
105
|
* [#27](https://github.com/aq1018/mongoid-history/pull/27): Added support for re-creation of destroyed embedded documents - [@erlingwl](https://github.com/erlingwl)
|
99
106
|
|
100
|
-
0.1.7 (12/
|
101
|
-
|
107
|
+
0.1.7 (2011/12/09)
|
108
|
+
------------------
|
102
109
|
|
103
110
|
* Fix: tracking `false` values - [@gottfrois](https://github.com/gottfrois).
|
104
|
-
*
|
111
|
+
* Used a mongoid observer and controller `around_filter` to pick up modifying user from controller - [@bensymonds](https://github.com/bensymonds).
|
105
112
|
* More flexible dependency on mongoid - [@sarcilav](https://github.com/sarcilav).
|
106
113
|
* Fix: tracking broken in a multithreaded environment - [@dblock](https://github.com/dblock).
|
107
114
|
|
108
|
-
0.1.0 (
|
109
|
-
|
115
|
+
0.1.0 (2011/05/13)
|
116
|
+
------------------
|
110
117
|
|
111
118
|
* Added support for `destroy` - [@dblock](https://github.com/dblock).
|
112
119
|
* Added undo and redo - [@aq1018](https://github.com/aq1018).
|
113
120
|
* Added support for temporarily disabling history tracking - [@aq1018](https://github.com/aq1018).
|
114
121
|
* Record modifier for undo and redo actions - [@aq1018](https://github.com/aq1018).
|
115
122
|
|
116
|
-
0.0.1 (
|
117
|
-
|
123
|
+
0.0.1 (2011/03/04)
|
124
|
+
------------------
|
118
125
|
|
119
126
|
* Intial public release - [@aq1018](https://github.com/aq1018).
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -11,15 +11,10 @@ Mongoid-history tracks historical changes for any document, including embedded o
|
|
11
11
|
|
12
12
|
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 (but we won't stop you either).
|
13
13
|
|
14
|
-
Stable Release
|
15
|
-
--------------
|
16
|
-
|
17
|
-
You're reading the documentation the 0.4.x release that supports Mongoid 3.x and 4.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).
|
18
|
-
|
19
14
|
Install
|
20
15
|
-------
|
21
16
|
|
22
|
-
This gem supports Mongoid 3
|
17
|
+
This gem supports Mongoid 3, 4 and 5 on Ruby 1.9.3 or newer. Add it to your `Gemfile` or run `gem install mongoid-history`.
|
23
18
|
|
24
19
|
```ruby
|
25
20
|
gem 'mongoid-history'
|
@@ -69,6 +64,7 @@ class Post
|
|
69
64
|
embeds_many :comments
|
70
65
|
|
71
66
|
# telling Mongoid::History how you want to track changes
|
67
|
+
# dynamic fields will be tracked automatically (for MongoId 4.0+ you should include Mongoid::Attributes::Dynamic to your model)
|
72
68
|
track_history :on => [:title, :body], # track title and body fields only, default is :all
|
73
69
|
:modifier_field => :modifier, # adds "belongs_to :modifier" to track who made the change, default is :modifier
|
74
70
|
:modifier_field_inverse_of => :nil, # adds an ":inverse_of" option to the "belongs_to :modifier" relation, default is not set
|
@@ -269,8 +265,31 @@ and nested attributes, you may wish to write your own changes method that includ
|
|
269
265
|
|
270
266
|
Mongoid::History provides an option named `:changes_method` which allows you to do this. It defaults to `:changes`, which is the standard changes method.
|
271
267
|
|
268
|
+
Note: Specify additional fields that are provided with a custom `changes_method` with the `:on` option.. To specify current fields and additional fields, use `fields.keys + [:custom]`
|
269
|
+
|
272
270
|
Example:
|
273
271
|
|
272
|
+
```ruby
|
273
|
+
class Foo
|
274
|
+
include Mongoid::Document
|
275
|
+
include Mongoid::History::Trackable
|
276
|
+
|
277
|
+
attr_accessor :ip
|
278
|
+
|
279
|
+
track_history on: [:ip], changes_method: :my_changes
|
280
|
+
|
281
|
+
def my_changes
|
282
|
+
unless ip.nil?
|
283
|
+
changes.merge(ip: [nil, ip])
|
284
|
+
else
|
285
|
+
changes
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
291
|
+
Example with embedded & nested attributes:
|
292
|
+
|
274
293
|
```ruby
|
275
294
|
class Foo
|
276
295
|
include Mongoid::Document
|
@@ -283,11 +302,11 @@ class Foo
|
|
283
302
|
|
284
303
|
# use changes_with_baz to include baz's changes in this document's
|
285
304
|
# history.
|
286
|
-
track_history
|
305
|
+
track_history on: fields.keys + [:baz], changes_method: :changes_with_baz
|
287
306
|
|
288
307
|
def changes_with_baz
|
289
308
|
if baz.changed?
|
290
|
-
changes.merge(
|
309
|
+
changes.merge(baz: summarized_changes(baz))
|
291
310
|
else
|
292
311
|
changes
|
293
312
|
end
|
data/Rakefile
CHANGED
data/lib/mongoid/history.rb
CHANGED
@@ -54,6 +54,10 @@ module Mongoid
|
|
54
54
|
Mongoid::History.enabled? && Thread.current[track_history_flag] != false
|
55
55
|
end
|
56
56
|
|
57
|
+
def dynamic_enabled?
|
58
|
+
Mongoid::Compatibility::Version.mongoid3? || (self < Mongoid::Attributes::Dynamic).present?
|
59
|
+
end
|
60
|
+
|
57
61
|
def disable_tracking(&_block)
|
58
62
|
Thread.current[track_history_flag] = false
|
59
63
|
yield
|
@@ -68,7 +72,10 @@ module Mongoid
|
|
68
72
|
|
69
73
|
module MyInstanceMethods
|
70
74
|
def history_tracks
|
71
|
-
@history_tracks ||= Mongoid::History.tracker_class.where(
|
75
|
+
@history_tracks ||= Mongoid::History.tracker_class.where(
|
76
|
+
scope: related_scope,
|
77
|
+
association_chain: association_hash
|
78
|
+
).asc(:version)
|
72
79
|
end
|
73
80
|
|
74
81
|
# undo :from => 1, :to => 5
|
@@ -80,7 +87,7 @@ module Mongoid
|
|
80
87
|
|
81
88
|
versions.each do |v|
|
82
89
|
undo_attr = v.undo_attr(modifier)
|
83
|
-
if Mongoid::
|
90
|
+
if Mongoid::Compatibility::Version.mongoid3? # update_attributes! not bypassing rails 3 protected attributes
|
84
91
|
assign_attributes(undo_attr, without_protection: true)
|
85
92
|
else # assign_attributes with 'without_protection' option does not work with rails 4/mongoid 4
|
86
93
|
self.attributes = undo_attr
|
@@ -102,7 +109,7 @@ module Mongoid
|
|
102
109
|
|
103
110
|
versions.each do |v|
|
104
111
|
redo_attr = v.redo_attr(modifier)
|
105
|
-
if Mongoid::
|
112
|
+
if Mongoid::Compatibility::Version.mongoid3?
|
106
113
|
assign_attributes(redo_attr, without_protection: true)
|
107
114
|
save!
|
108
115
|
else
|
@@ -126,7 +133,7 @@ module Mongoid
|
|
126
133
|
options = options_or_version
|
127
134
|
if options[:from] && options[:to]
|
128
135
|
lower = options[:from] >= options[:to] ? options[:to] : options[:from]
|
129
|
-
upper = options[:from] <
|
136
|
+
upper = options[:from] < options[:to] ? options[:to] : options[:from]
|
130
137
|
versions = history_tracks.where(:version.in => (lower..upper).to_a)
|
131
138
|
elsif options[:last]
|
132
139
|
versions = history_tracks.limit(options[:last])
|
@@ -147,12 +154,12 @@ module Mongoid
|
|
147
154
|
scope = history_trackable_options[:scope]
|
148
155
|
|
149
156
|
# Use top level document if its name is specified in the scope
|
150
|
-
root_document_name = traverse_association_chain.first['name'].singularize.underscore.
|
157
|
+
root_document_name = traverse_association_chain.first['name'].singularize.underscore.tr('/', '_').to_sym
|
151
158
|
if scope.is_a?(Array) && scope.include?(root_document_name)
|
152
159
|
scope = root_document_name
|
153
160
|
else
|
154
161
|
scope = _parent.collection_name.to_s.singularize.to_sym if scope.is_a?(Array)
|
155
|
-
if Mongoid::
|
162
|
+
if Mongoid::Compatibility::Version.mongoid3?
|
156
163
|
scope = metadata.inverse_class_name.tableize.singularize.to_sym if metadata.present? && scope == metadata.as
|
157
164
|
else
|
158
165
|
scope = relation_metadata.inverse_class_name.tableize.singularize.to_sym if relation_metadata.present? && scope == relation_metadata.as
|
@@ -173,14 +180,14 @@ module Mongoid
|
|
173
180
|
# we're assured, through the object creation, it'll exist. Whereas we're not guarenteed
|
174
181
|
# the child to parent (embedded_in, belongs_to) relation will be defined
|
175
182
|
if node._parent
|
176
|
-
meta = node._parent.relations.values.
|
177
|
-
if Mongoid::
|
183
|
+
meta = node._parent.relations.values.find do |relation|
|
184
|
+
if Mongoid::Compatibility::Version.mongoid3?
|
178
185
|
relation.class_name == node.metadata.class_name.to_s && relation.name == node.metadata.name
|
179
186
|
else
|
180
187
|
relation.class_name == node.relation_metadata.class_name.to_s &&
|
181
188
|
relation.name == node.relation_metadata.name
|
182
189
|
end
|
183
|
-
end
|
190
|
+
end
|
184
191
|
end
|
185
192
|
|
186
193
|
# if root node has no meta, and should use class name instead
|
@@ -251,7 +258,7 @@ module Mongoid
|
|
251
258
|
end
|
252
259
|
|
253
260
|
def clear_trackable_memoization
|
254
|
-
@history_tracker_attributes =
|
261
|
+
@history_tracker_attributes = nil
|
255
262
|
@modified_attributes_for_create = nil
|
256
263
|
@modified_attributes_for_update = nil
|
257
264
|
@history_tracks = nil
|
@@ -293,7 +300,16 @@ module Mongoid
|
|
293
300
|
#
|
294
301
|
# @return [ Boolean ] whether or not the field is tracked for the given action
|
295
302
|
def tracked_field?(field, action = :update)
|
296
|
-
tracked_fields_for_action(action).include?
|
303
|
+
dynamic_field?(field) || tracked_fields_for_action(action).include?(database_field_name(field))
|
304
|
+
end
|
305
|
+
|
306
|
+
# Checks if field is dynamic.
|
307
|
+
#
|
308
|
+
# @param [ String | Symbol ] field The name of the dynamic field
|
309
|
+
#
|
310
|
+
# @return [ Boolean ] whether or not the field is dynamic
|
311
|
+
def dynamic_field?(field)
|
312
|
+
dynamic_enabled? && !fields.keys.include?(database_field_name(field))
|
297
313
|
end
|
298
314
|
|
299
315
|
# Retrieves the list of tracked fields for a given action.
|
@@ -312,10 +328,10 @@ module Mongoid
|
|
312
328
|
#
|
313
329
|
# @return [ Array < String > ] the base list of tracked database field names
|
314
330
|
def tracked_fields
|
315
|
-
@tracked_fields ||=
|
331
|
+
@tracked_fields ||= begin
|
316
332
|
h = history_trackable_options
|
317
|
-
(h[:on] == :all
|
318
|
-
end
|
333
|
+
(h[:on] == :all ? fields.keys : h[:on]) - h[:except] - reserved_tracked_fields
|
334
|
+
end
|
319
335
|
end
|
320
336
|
|
321
337
|
# Retrieves the memoized list of reserved tracked fields, which are only included for certain actions.
|