mongoid-history 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +47 -38
- data/CHANGELOG.md +5 -0
- data/Gemfile +6 -5
- data/README.md +53 -2
- data/RELEASING.md +68 -0
- data/Rakefile +1 -1
- data/UPGRADING.md +9 -0
- data/lib/mongoid/history.rb +1 -1
- data/lib/mongoid/history/attributes/create.rb +2 -2
- data/lib/mongoid/history/attributes/destroy.rb +9 -9
- data/lib/mongoid/history/attributes/update.rb +2 -2
- data/lib/mongoid/history/options.rb +4 -4
- data/lib/mongoid/history/trackable.rb +27 -16
- data/lib/mongoid/history/tracker.rb +8 -6
- data/lib/mongoid/history/version.rb +1 -1
- data/spec/integration/embedded_in_polymorphic_spec.rb +1 -1
- data/spec/integration/integration_spec.rb +10 -10
- data/spec/integration/multi_relation_spec.rb +1 -1
- data/spec/integration/multiple_trackers_spec.rb +71 -0
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +2 -2
- data/spec/integration/validation_failure_spec.rb +63 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/attributes/base_spec.rb +3 -3
- data/spec/unit/my_instance_methods_spec.rb +1 -1
- data/spec/unit/options_spec.rb +52 -52
- data/spec/unit/singleton_methods_spec.rb +13 -13
- data/spec/unit/trackable_spec.rb +66 -7
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2d2105bf114627851d9fca6f7b7117f4766b0d9
|
4
|
+
data.tar.gz: bfc95d7ddcfcdd2b977f799641d63b61d2da3b45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2a0ef3daab0538b8d7a853f3e1c1f40d10a244521fd9811ee6feff55529ae1d58d685126262510bc0311da2bb0184f6c5b1d883accbd02742e665346ab84b93
|
7
|
+
data.tar.gz: d2358b6e8625a06aa1a52a1de2783d15b4a86cfb3b644055912ecae13063cc951c22440f38e9837c43810e780c8f220ff10936e8558fdf57be8ca6b2d4afd38c
|
data/.rubocop_todo.yml
CHANGED
@@ -1,92 +1,101 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2017-04-09 18:25:15 -0400 using RuboCop version 0.48.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 6
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/Gemfile, **/gems.rb
|
12
|
+
Bundler/DuplicatedGem:
|
13
|
+
Exclude:
|
14
|
+
- 'Gemfile'
|
15
|
+
|
9
16
|
# Offense count: 3
|
10
17
|
Lint/HandleExceptions:
|
11
18
|
Exclude:
|
12
19
|
- 'spec/unit/trackable_spec.rb'
|
13
20
|
|
14
|
-
|
15
|
-
|
21
|
+
# Offense count: 2
|
22
|
+
Lint/ParenthesesAsGroupedExpression:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/integration/integration_spec.rb'
|
16
25
|
|
17
|
-
# Offense count:
|
26
|
+
# Offense count: 21
|
18
27
|
Metrics/AbcSize:
|
19
|
-
Max:
|
28
|
+
Max: 50
|
29
|
+
|
30
|
+
# Offense count: 100
|
31
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
32
|
+
Metrics/BlockLength:
|
33
|
+
Max: 801
|
34
|
+
|
35
|
+
# Offense count: 1
|
36
|
+
# Configuration parameters: CountComments.
|
37
|
+
Metrics/ClassLength:
|
38
|
+
Max: 124
|
20
39
|
|
21
40
|
# Offense count: 4
|
22
41
|
Metrics/CyclomaticComplexity:
|
23
42
|
Max: 10
|
24
43
|
|
25
|
-
# Offense count:
|
26
|
-
# Configuration parameters: AllowURI, URISchemes.
|
44
|
+
# Offense count: 435
|
45
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
46
|
+
# URISchemes: http, https
|
27
47
|
Metrics/LineLength:
|
28
48
|
Max: 688
|
29
49
|
|
30
|
-
# Offense count:
|
50
|
+
# Offense count: 13
|
31
51
|
# Configuration parameters: CountComments.
|
32
52
|
Metrics/MethodLength:
|
33
|
-
Max:
|
53
|
+
Max: 23
|
34
54
|
|
35
55
|
# Offense count: 2
|
36
56
|
# Configuration parameters: CountComments.
|
37
57
|
Metrics/ModuleLength:
|
38
|
-
Max:
|
58
|
+
Max: 176
|
39
59
|
|
40
60
|
# Offense count: 4
|
41
61
|
Metrics/PerceivedComplexity:
|
42
62
|
Max: 12
|
43
63
|
|
44
|
-
# Offense count:
|
64
|
+
# Offense count: 12
|
45
65
|
Style/Documentation:
|
46
66
|
Exclude:
|
67
|
+
- 'spec/**/*'
|
68
|
+
- 'test/**/*'
|
47
69
|
- 'lib/mongoid/history.rb'
|
48
|
-
- 'lib/mongoid/history/options.rb'
|
49
|
-
- 'lib/mongoid/history/trackable.rb'
|
50
|
-
- 'lib/mongoid/history/tracker.rb'
|
51
|
-
- 'lib/mongoid/history/version.rb'
|
52
70
|
- 'lib/mongoid/history/attributes/base.rb'
|
53
71
|
- 'lib/mongoid/history/attributes/create.rb'
|
54
72
|
- 'lib/mongoid/history/attributes/destroy.rb'
|
55
73
|
- 'lib/mongoid/history/attributes/update.rb'
|
56
|
-
- '
|
57
|
-
- '
|
58
|
-
- '
|
59
|
-
- 'spec/integration/nested_embedded_documents_spec.rb'
|
60
|
-
- 'spec/integration/nested_embedded_polymorphic_documents_spec.rb'
|
61
|
-
- 'spec/integration/subclasses_spec.rb'
|
62
|
-
- 'spec/support/mongoid_history.rb'
|
63
|
-
- 'spec/unit/options_spec.rb'
|
64
|
-
- 'spec/unit/singleton_methods_spec.rb'
|
65
|
-
- 'spec/unit/trackable_spec.rb'
|
66
|
-
- 'spec/unit/tracker_spec.rb'
|
67
|
-
- 'spec/unit/attributes/base_spec.rb'
|
68
|
-
- 'spec/unit/attributes/create_spec.rb'
|
69
|
-
- 'spec/unit/attributes/destroy_spec.rb'
|
70
|
-
- 'spec/unit/attributes/update_spec.rb'
|
74
|
+
- 'lib/mongoid/history/options.rb'
|
75
|
+
- 'lib/mongoid/history/trackable.rb'
|
76
|
+
- 'lib/mongoid/history/tracker.rb'
|
71
77
|
|
72
|
-
# Offense count:
|
78
|
+
# Offense count: 3
|
79
|
+
# Cop supports --auto-correct.
|
73
80
|
Style/EachWithObject:
|
74
81
|
Exclude:
|
75
82
|
- 'lib/mongoid/history/trackable.rb'
|
76
83
|
- 'lib/mongoid/history/tracker.rb'
|
77
84
|
|
78
|
-
# Offense count:
|
79
|
-
# Configuration parameters:
|
85
|
+
# Offense count: 2
|
86
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
87
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
80
88
|
Style/FileName:
|
81
89
|
Exclude:
|
90
|
+
- 'Dangerfile'
|
82
91
|
- 'lib/mongoid-history.rb'
|
83
92
|
|
84
|
-
# Offense count:
|
85
|
-
Style/
|
93
|
+
# Offense count: 1
|
94
|
+
Style/IfInsideElse:
|
86
95
|
Exclude:
|
87
96
|
- 'lib/mongoid/history/trackable.rb'
|
88
|
-
- 'lib/mongoid/history/tracker.rb'
|
89
97
|
|
90
|
-
|
98
|
+
# Offense count: 1
|
99
|
+
Style/MultilineBlockChain:
|
91
100
|
Exclude:
|
92
|
-
- 'lib/mongoid/history/
|
101
|
+
- 'lib/mongoid/history/tracker.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.7.0 (2017/11/14)
|
2
|
+
|
3
|
+
* [#202](https://github.com/mongoid/mongoid-history/pull/202): Do not create tracker on persistence error - [@mikwat](https://github.com/mikwat).
|
4
|
+
* [#196](https://github.com/mongoid/mongoid-history/pull/196): Fix bug causing history tracks to get mixed up between multiple trackers when using multiple trackers - [@ojbucao](https://github.com/ojbucao).
|
5
|
+
|
1
6
|
### 0.6.1 (2017/01/04)
|
2
7
|
|
3
8
|
* [#182](https://github.com/mongoid/mongoid-history/pull/182): No-op on repeated calls to destroy - [@msaffitz](https://github.com/msaffitz).
|
data/Gemfile
CHANGED
@@ -20,16 +20,17 @@ else
|
|
20
20
|
end
|
21
21
|
|
22
22
|
group :development, :test do
|
23
|
-
gem 'rake', '< 11.0'
|
24
23
|
gem 'bundler'
|
24
|
+
gem 'pry'
|
25
|
+
gem 'rake', '< 11.0'
|
25
26
|
end
|
26
27
|
|
27
28
|
group :test do
|
29
|
+
gem 'coveralls'
|
30
|
+
gem 'gem-release'
|
28
31
|
gem 'mongoid-danger', '~> 0.1.0', require: false
|
32
|
+
gem 'request_store'
|
29
33
|
gem 'rspec', '~> 3.1'
|
30
|
-
gem 'rubocop', '0.
|
34
|
+
gem 'rubocop', '0.48.1'
|
31
35
|
gem 'yard'
|
32
|
-
gem 'gem-release'
|
33
|
-
gem 'coveralls'
|
34
|
-
gem 'request_store'
|
35
36
|
end
|
data/README.md
CHANGED
@@ -37,8 +37,8 @@ end
|
|
37
37
|
**Set default tracker class name (Optional)**
|
38
38
|
|
39
39
|
Mongoid::History will use the first loaded class to include Mongoid::History::Tracker as the
|
40
|
-
default history tracker. If you are using multiple Tracker classes
|
41
|
-
|
40
|
+
default history tracker. If you are using multiple Tracker classes, you should set a global
|
41
|
+
default in a Rails initializer:
|
42
42
|
|
43
43
|
```ruby
|
44
44
|
# config/initializers/mongoid_history.rb
|
@@ -509,6 +509,57 @@ end
|
|
509
509
|
|
510
510
|
For more examples, check out [spec/integration/integration_spec.rb](spec/integration/integration_spec.rb).
|
511
511
|
|
512
|
+
**Multiple Trackers**
|
513
|
+
|
514
|
+
You can have different trackers for different classes like so.
|
515
|
+
|
516
|
+
```
|
517
|
+
class First
|
518
|
+
include Mongoid::Document
|
519
|
+
include Mongoid::History::Trackable
|
520
|
+
|
521
|
+
field :text, type: String
|
522
|
+
track_history on: [:text],
|
523
|
+
tracker_class_name: :first_history_tracker
|
524
|
+
end
|
525
|
+
|
526
|
+
class Second
|
527
|
+
include Mongoid::Document
|
528
|
+
include Mongoid::History::Trackable
|
529
|
+
|
530
|
+
field :text, type: String
|
531
|
+
track_history on: [:text],
|
532
|
+
tracker_class_name: :second_history_tracker
|
533
|
+
end
|
534
|
+
|
535
|
+
class FirstHistoryTracker
|
536
|
+
include Mongoid::History::Tracker
|
537
|
+
end
|
538
|
+
|
539
|
+
class SecondHistoryTracker
|
540
|
+
include Mongoid::History::Tracker
|
541
|
+
end
|
542
|
+
```
|
543
|
+
|
544
|
+
Note that if you are using a tracker for an embedded object that is different
|
545
|
+
from the parent's tracker, redos and undos will not work. You have to use the
|
546
|
+
same tracker for these to work across embedded relationships.
|
547
|
+
|
548
|
+
If you are using multiple trackers and the `tracker_class_name` parameter is
|
549
|
+
not specified, Mongoid::History will use the default tracker configured in the
|
550
|
+
initializer file or whatever the first tracker was loaded.
|
551
|
+
|
552
|
+
|
553
|
+
**Dependent Restrict Associations**
|
554
|
+
|
555
|
+
When `dependent: :restrict` is used on an association, a call to `destroy` on
|
556
|
+
the model will raise `Mongoid::Errors::DeleteRestriction` when the dependency
|
557
|
+
is violated. Just be aware that this gem will create a history track document
|
558
|
+
before the `destroy` call and then remove if an error is raised. This applies
|
559
|
+
to all persistence calls: create, update and destroy.
|
560
|
+
|
561
|
+
See [spec/integration/validation_failure_spec.rb](spec/integration/validation_failure_spec.rb)
|
562
|
+
for examples.
|
512
563
|
|
513
564
|
**Thread Safety**
|
514
565
|
|
data/RELEASING.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
Releasing Mongoid::History
|
2
|
+
========================
|
3
|
+
|
4
|
+
There're no particular rules about when to release mongoid-history. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
5
|
+
|
6
|
+
### Release
|
7
|
+
|
8
|
+
Run tests, check that all tests succeed locally.
|
9
|
+
|
10
|
+
```
|
11
|
+
bundle install
|
12
|
+
bundle exec rake
|
13
|
+
```
|
14
|
+
|
15
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/mongoid/mongoid-history) for all supported platforms.
|
16
|
+
|
17
|
+
Increment the version, modify [lib/mongoid/history/version.rb](lib/mongoid/history/version.rb).
|
18
|
+
|
19
|
+
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`).
|
20
|
+
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.4.0`).
|
21
|
+
|
22
|
+
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
23
|
+
|
24
|
+
```
|
25
|
+
### 0.4.0 (2014-01-27)
|
26
|
+
```
|
27
|
+
|
28
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
29
|
+
|
30
|
+
Commit your changes.
|
31
|
+
|
32
|
+
```
|
33
|
+
git add CHANGELOG.md lib/mongoid/history/version.rb
|
34
|
+
git commit -m "Preparing for release, 0.4.0."
|
35
|
+
git push origin master
|
36
|
+
```
|
37
|
+
|
38
|
+
Release.
|
39
|
+
|
40
|
+
```
|
41
|
+
$ rake release
|
42
|
+
|
43
|
+
mongoid-history 0.4.0 built to pkg/mongoid-history-0.4.0.gem.
|
44
|
+
Tagged v0.4.0.
|
45
|
+
Pushed git commits and tags.
|
46
|
+
Pushed mongoid-history 0.4.0 to rubygems.org.
|
47
|
+
```
|
48
|
+
|
49
|
+
### Prepare for the Next Version
|
50
|
+
|
51
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
52
|
+
|
53
|
+
```
|
54
|
+
Next Release
|
55
|
+
============
|
56
|
+
|
57
|
+
* Your contribution here.
|
58
|
+
```
|
59
|
+
|
60
|
+
Increment the minor version, modify [lib/mongoid/history/version.rb](lib/mongoid/history/version.rb).
|
61
|
+
|
62
|
+
Commit your changes.
|
63
|
+
|
64
|
+
```
|
65
|
+
git add CHANGELOG.md lib/mongoid/history/version.rb
|
66
|
+
git commit -m "Preparing for next release, 0.4.1."
|
67
|
+
git push origin master
|
68
|
+
```
|
data/Rakefile
CHANGED
data/UPGRADING.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
### Upgrading to 0.7.0
|
2
|
+
|
3
|
+
#### Remove history track when create, update or destroy raises an error
|
4
|
+
|
5
|
+
When an error is raised in a call to create, update or destroy a tracked model, any history track
|
6
|
+
created before the call will now be deleted. In the past this was a problem for associations marked
|
7
|
+
`dependent: :restrict`.
|
8
|
+
|
9
|
+
See [#202](https://github.com/mongoid/mongoid-history/pull/202) for more information.
|
data/lib/mongoid/history.rb
CHANGED
@@ -11,7 +11,7 @@ require 'mongoid/history/trackable'
|
|
11
11
|
|
12
12
|
module Mongoid
|
13
13
|
module History
|
14
|
-
GLOBAL_TRACK_HISTORY_FLAG = 'mongoid_history_trackable_enabled'
|
14
|
+
GLOBAL_TRACK_HISTORY_FLAG = 'mongoid_history_trackable_enabled'.freeze
|
15
15
|
|
16
16
|
class << self
|
17
17
|
attr_accessor :tracker_class_name
|
@@ -40,8 +40,8 @@ module Mongoid
|
|
40
40
|
rel = aliased_fields.key(rel) || rel
|
41
41
|
@attributes[rel] = [nil,
|
42
42
|
trackable.send(rel)
|
43
|
-
|
44
|
-
|
43
|
+
.reject { |obj| obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present? }
|
44
|
+
.map { |obj| format_embeds_many_relation(rel, obj.attributes) }]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -14,19 +14,19 @@ module Mongoid
|
|
14
14
|
|
15
15
|
def insert_embeds_one_changes
|
16
16
|
trackable_class.tracked_embeds_one
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
.map { |rel| aliased_fields.key(rel) || rel }
|
18
|
+
.each do |rel|
|
19
|
+
obj = trackable.send(rel)
|
20
|
+
@attributes[rel] = [format_embeds_one_relation(rel, obj.attributes), nil] if obj
|
21
|
+
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def insert_embeds_many_changes
|
25
25
|
trackable_class.tracked_embeds_many
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
.map { |rel| aliased_fields.key(rel) || rel }
|
27
|
+
.each do |rel|
|
28
|
+
@attributes[rel] = [trackable.send(rel).map { |obj| format_embeds_many_relation(rel, obj.attributes) }, nil]
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -33,9 +33,9 @@ module Mongoid
|
|
33
33
|
paranoia_field = Mongoid::History.trackable_class_settings(relation_class)[:paranoia_field]
|
34
34
|
@attributes[relation] = []
|
35
35
|
@attributes[relation][0] = value[0].reject { |rel| rel[paranoia_field].present? }
|
36
|
-
|
36
|
+
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
|
37
37
|
@attributes[relation][1] = value[1].reject { |rel| rel[paranoia_field].present? }
|
38
|
-
|
38
|
+
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -24,7 +24,7 @@ module Mongoid
|
|
24
24
|
def default_options
|
25
25
|
@default_options ||=
|
26
26
|
{ on: :all,
|
27
|
-
except: [
|
27
|
+
except: %i[created_at updated_at],
|
28
28
|
tracker_class_name: nil,
|
29
29
|
modifier_field: :modifier,
|
30
30
|
version_field: :version,
|
@@ -83,7 +83,7 @@ module Mongoid
|
|
83
83
|
Going forward, :all will track all the fields and relations for the class"
|
84
84
|
end
|
85
85
|
|
86
|
-
@options[:on] = options[:on].map { |opt|
|
86
|
+
@options[:on] = options[:on].map { |opt| opt == :all ? :fields : opt }
|
87
87
|
|
88
88
|
if options[:on].include?(:fields)
|
89
89
|
@options[:on] = options[:on].reject { |opt| opt == :fields }
|
@@ -163,7 +163,7 @@ module Mongoid
|
|
163
163
|
@options[:relations][:embeds_one][field] = if field_options.blank?
|
164
164
|
relation_class.fields.keys
|
165
165
|
else
|
166
|
-
%w
|
166
|
+
%w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) }
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
@@ -172,7 +172,7 @@ module Mongoid
|
|
172
172
|
@options[:relations][:embeds_many][field] = if field_options.blank?
|
173
173
|
relation_class.fields.keys
|
174
174
|
else
|
175
|
-
%w
|
175
|
+
%w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) }
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
@@ -22,9 +22,9 @@ module Mongoid
|
|
22
22
|
delegate :history_trackable_options, to: 'self.class'
|
23
23
|
delegate :track_history?, to: 'self.class'
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
around_update :track_update if options[:track_update]
|
26
|
+
around_create :track_create if options[:track_create]
|
27
|
+
around_destroy :track_destroy if options[:track_destroy]
|
28
28
|
|
29
29
|
Mongoid::History.trackable_class_options ||= {}
|
30
30
|
Mongoid::History.trackable_class_options[options_parser.scope] = options
|
@@ -131,7 +131,7 @@ module Mongoid
|
|
131
131
|
elsif options[:last]
|
132
132
|
versions = history_tracks.limit(options[:last])
|
133
133
|
else
|
134
|
-
|
134
|
+
raise 'Invalid options, please specify (:from / :to) keys or :last key.'
|
135
135
|
end
|
136
136
|
else
|
137
137
|
options_or_version = options_or_version.to_a if options_or_version.is_a?(Range)
|
@@ -178,7 +178,7 @@ module Mongoid
|
|
178
178
|
relation.class_name == node.metadata.class_name.to_s && relation.name == node.metadata.name
|
179
179
|
else
|
180
180
|
relation.class_name == node.relation_metadata.class_name.to_s &&
|
181
|
-
|
181
|
+
relation.name == node.relation_metadata.name
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
@@ -232,16 +232,16 @@ module Mongoid
|
|
232
232
|
@history_tracker_attributes
|
233
233
|
end
|
234
234
|
|
235
|
-
def track_create
|
236
|
-
track_history_for_action(:create)
|
235
|
+
def track_create(&block)
|
236
|
+
track_history_for_action(:create, &block)
|
237
237
|
end
|
238
238
|
|
239
|
-
def track_update
|
240
|
-
track_history_for_action(:update)
|
239
|
+
def track_update(&block)
|
240
|
+
track_history_for_action(:update, &block)
|
241
241
|
end
|
242
242
|
|
243
|
-
def track_destroy
|
244
|
-
track_history_for_action(:destroy) unless destroyed?
|
243
|
+
def track_destroy(&block)
|
244
|
+
track_history_for_action(:destroy, &block) unless destroyed?
|
245
245
|
end
|
246
246
|
|
247
247
|
def clear_trackable_memoization
|
@@ -273,9 +273,20 @@ module Mongoid
|
|
273
273
|
if track_history_for_action?(action)
|
274
274
|
current_version = (send(history_trackable_options[:version_field]) || 0) + 1
|
275
275
|
send("#{history_trackable_options[:version_field]}=", current_version)
|
276
|
-
self.class.tracker_class.create!(history_tracker_attributes(action.to_sym).merge(version: current_version, action: action.to_s, trackable: self))
|
276
|
+
last_track = self.class.tracker_class.create!(history_tracker_attributes(action.to_sym).merge(version: current_version, action: action.to_s, trackable: self))
|
277
277
|
end
|
278
|
+
|
278
279
|
clear_trackable_memoization
|
280
|
+
|
281
|
+
begin
|
282
|
+
yield
|
283
|
+
rescue => e
|
284
|
+
if track_history_for_action?(action)
|
285
|
+
send("#{history_trackable_options[:version_field]}=", current_version - 1)
|
286
|
+
last_track.destroy
|
287
|
+
end
|
288
|
+
raise e
|
289
|
+
end
|
279
290
|
end
|
280
291
|
end
|
281
292
|
|
@@ -445,8 +456,8 @@ module Mongoid
|
|
445
456
|
def tracked_embeds_one
|
446
457
|
@tracked_embeds_one ||= begin
|
447
458
|
reflect_on_all_associations(:embeds_one)
|
448
|
-
|
449
|
-
|
459
|
+
.map(&:key)
|
460
|
+
.select { |rel| history_trackable_options[:relations][:embeds_one].include? rel }
|
450
461
|
end
|
451
462
|
end
|
452
463
|
|
@@ -469,8 +480,8 @@ module Mongoid
|
|
469
480
|
def tracked_embeds_many
|
470
481
|
@tracked_embeds_many ||= begin
|
471
482
|
reflect_on_all_associations(:embeds_many)
|
472
|
-
|
473
|
-
|
483
|
+
.map(&:key)
|
484
|
+
.select { |rel| history_trackable_options[:relations][:embeds_many].include? rel }
|
474
485
|
end
|
475
486
|
end
|
476
487
|
|