mongoid-history 0.8.3 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -1
- data/.document +5 -5
- data/.github/workflows/test.yml +72 -0
- data/.gitignore +46 -46
- data/.rspec +2 -2
- data/.rubocop.yml +6 -6
- data/.rubocop_todo.yml +99 -99
- data/CHANGELOG.md +173 -163
- data/CONTRIBUTING.md +117 -118
- data/Dangerfile +1 -1
- data/Gemfile +49 -40
- data/LICENSE.txt +20 -20
- data/README.md +609 -608
- data/RELEASING.md +66 -67
- data/Rakefile +24 -24
- data/UPGRADING.md +53 -53
- data/lib/mongoid/history/attributes/base.rb +72 -72
- data/lib/mongoid/history/attributes/create.rb +45 -45
- data/lib/mongoid/history/attributes/destroy.rb +34 -34
- data/lib/mongoid/history/attributes/update.rb +104 -104
- data/lib/mongoid/history/options.rb +177 -177
- data/lib/mongoid/history/trackable.rb +588 -583
- data/lib/mongoid/history/tracker.rb +247 -247
- data/lib/mongoid/history/version.rb +5 -5
- data/lib/mongoid/history.rb +77 -77
- data/lib/mongoid-history.rb +1 -1
- data/mongoid-history.gemspec +25 -25
- data/perf/benchmark_modified_attributes_for_create.rb +65 -65
- data/perf/gc_suite.rb +21 -21
- data/spec/integration/embedded_in_polymorphic_spec.rb +112 -112
- data/spec/integration/integration_spec.rb +976 -976
- data/spec/integration/multi_relation_spec.rb +47 -47
- data/spec/integration/multiple_trackers_spec.rb +68 -68
- data/spec/integration/nested_embedded_documents_spec.rb +64 -64
- data/spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb +124 -124
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +115 -115
- data/spec/integration/subclasses_spec.rb +47 -47
- data/spec/integration/track_history_order_spec.rb +84 -84
- data/spec/integration/validation_failure_spec.rb +76 -76
- data/spec/spec_helper.rb +32 -30
- data/spec/support/error_helpers.rb +7 -0
- data/spec/support/mongoid.rb +11 -11
- data/spec/support/mongoid_history.rb +12 -12
- data/spec/unit/attributes/base_spec.rb +141 -141
- data/spec/unit/attributes/create_spec.rb +342 -342
- data/spec/unit/attributes/destroy_spec.rb +228 -228
- data/spec/unit/attributes/update_spec.rb +342 -342
- data/spec/unit/callback_options_spec.rb +165 -165
- data/spec/unit/embedded_methods_spec.rb +87 -87
- data/spec/unit/history_spec.rb +58 -58
- data/spec/unit/my_instance_methods_spec.rb +555 -555
- data/spec/unit/options_spec.rb +365 -365
- data/spec/unit/singleton_methods_spec.rb +406 -406
- data/spec/unit/store/default_store_spec.rb +11 -11
- data/spec/unit/store/request_store_spec.rb +13 -13
- data/spec/unit/trackable_spec.rb +1057 -987
- data/spec/unit/tracker_spec.rb +190 -190
- metadata +9 -7
- data/.travis.yml +0 -36
data/RELEASING.md
CHANGED
@@ -1,67 +1,66 @@
|
|
1
|
-
Releasing Mongoid::History
|
2
|
-
|
3
|
-
|
4
|
-
|
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)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
git
|
34
|
-
git
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
Pushed
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
git
|
65
|
-
git
|
66
|
-
|
67
|
-
```
|
1
|
+
# Releasing Mongoid::History
|
2
|
+
|
3
|
+
There are no particular rules about when to release Mongoid History.
|
4
|
+
Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
5
|
+
|
6
|
+
### Release Procedure
|
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)
|
16
|
+
for all supported platforms.
|
17
|
+
|
18
|
+
Increment the version, modify [lib/mongoid/history/version.rb](lib/mongoid/history/version.rb).
|
19
|
+
Mongoid History versions should follow [Semantic Versioning (SemVer)](https://semver.org/).
|
20
|
+
|
21
|
+
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
22
|
+
|
23
|
+
```
|
24
|
+
### 0.4.0 (2014-01-27)
|
25
|
+
```
|
26
|
+
|
27
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
28
|
+
|
29
|
+
Commit your changes.
|
30
|
+
|
31
|
+
```
|
32
|
+
git add CHANGELOG.md lib/mongoid/history/version.rb
|
33
|
+
git commit -m "Preparing for release, 0.4.0."
|
34
|
+
git push origin master
|
35
|
+
```
|
36
|
+
|
37
|
+
Release.
|
38
|
+
|
39
|
+
```
|
40
|
+
$ rake release
|
41
|
+
|
42
|
+
mongoid-history 0.4.0 built to pkg/mongoid-history-0.4.0.gem.
|
43
|
+
Tagged v0.4.0.
|
44
|
+
Pushed git commits and tags.
|
45
|
+
Pushed mongoid-history 0.4.0 to rubygems.org.
|
46
|
+
```
|
47
|
+
|
48
|
+
### Prepare for the Next Version
|
49
|
+
|
50
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
51
|
+
|
52
|
+
```
|
53
|
+
### 0.4.1 (Next)
|
54
|
+
|
55
|
+
* Your contribution here.
|
56
|
+
```
|
57
|
+
|
58
|
+
Increment the minor version, modify [lib/mongoid/history/version.rb](lib/mongoid/history/version.rb).
|
59
|
+
|
60
|
+
Commit your changes.
|
61
|
+
|
62
|
+
```
|
63
|
+
git add CHANGELOG.md lib/mongoid/history/version.rb
|
64
|
+
git commit -m "Preparing for next release, 0.4.1."
|
65
|
+
git push origin master
|
66
|
+
```
|
data/Rakefile
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
begin
|
3
|
-
Bundler.setup(:default, :development)
|
4
|
-
rescue Bundler::BundlerError => e
|
5
|
-
$stderr.puts e.message
|
6
|
-
$stderr.puts 'Run `bundle install` to install missing gems'
|
7
|
-
exit e.status_code
|
8
|
-
end
|
9
|
-
|
10
|
-
Bundler::GemHelper.install_tasks
|
11
|
-
|
12
|
-
require 'rspec/core'
|
13
|
-
require 'rspec/core/rake_task'
|
14
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
15
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'rubocop/rake_task'
|
19
|
-
RuboCop::RakeTask.new(:rubocop)
|
20
|
-
|
21
|
-
task default: %i[rubocop spec]
|
22
|
-
|
23
|
-
require 'yard'
|
24
|
-
YARD::Rake::YardocTask.new
|
1
|
+
require 'bundler'
|
2
|
+
begin
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
7
|
+
exit e.status_code
|
8
|
+
end
|
9
|
+
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
15
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rubocop/rake_task'
|
19
|
+
RuboCop::RakeTask.new(:rubocop)
|
20
|
+
|
21
|
+
task default: %i[rubocop spec]
|
22
|
+
|
23
|
+
require 'yard'
|
24
|
+
YARD::Rake::YardocTask.new
|
data/UPGRADING.md
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
## Upgrading Mongoid History
|
2
|
-
|
3
|
-
### Upgrading to 0.8.0
|
4
|
-
|
5
|
-
#### History is now tracked on create and destroy by default
|
6
|
-
|
7
|
-
By default, Mongoid History will now track all actions (create, update, and destroy.)
|
8
|
-
Previously, only update actions were tracked by default.
|
9
|
-
|
10
|
-
To preserve the old behavior, please modify your call to `track_history` as follows:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
track_history ...
|
14
|
-
track_create: false,
|
15
|
-
track_destroy: false
|
16
|
-
```
|
17
|
-
|
18
|
-
See [#207](https://github.com/mongoid/mongoid-history/pull/207) for more information.
|
19
|
-
|
20
|
-
### Upgrading to 0.7.0
|
21
|
-
|
22
|
-
#### Remove history track when create, update or destroy raises an error
|
23
|
-
|
24
|
-
When an error is raised in a call to create, update or destroy a tracked model, any history track
|
25
|
-
created before the call will now be deleted. In the past this was a problem for associations marked
|
26
|
-
`dependent: :restrict`.
|
27
|
-
|
28
|
-
See [#202](https://github.com/mongoid/mongoid-history/pull/202) for more information.
|
29
|
-
|
30
|
-
# Main Changes / Upgrading Notes
|
31
|
-
|
32
|
-
See [#189](https://github.com/mongoid/mongoid-history/pull/189) for more information.
|
33
|
-
|
34
|
-
* Currently, the `:all` option behaves identically to `:fields`. Future versions will track all fields and relations of trackable class when using `:all`.
|
35
|
-
|
36
|
-
### Upgrading to 0.4.1
|
37
|
-
|
38
|
-
#### Migrate Userstamp
|
39
|
-
|
40
|
-
`Mongoid::History` no longer supports the userstamp natively. To track the User in the application who created the HistoryTracker, add the [Mongoid::Userstamp gem](https://github.com/tbpro/mongoid_userstamp) to your HistoryTracker class.
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
class MyHistoryTracker
|
44
|
-
include Mongoid::History::Tracker
|
45
|
-
include Mongoid::Userstamp
|
46
|
-
end
|
47
|
-
```
|
48
|
-
|
49
|
-
Rename the field.
|
50
|
-
|
51
|
-
```ruby
|
52
|
-
MyHistoryTracker.all.rename(modifier_id: :created_by)
|
53
|
-
```
|
1
|
+
## Upgrading Mongoid History
|
2
|
+
|
3
|
+
### Upgrading to 0.8.0
|
4
|
+
|
5
|
+
#### History is now tracked on create and destroy by default
|
6
|
+
|
7
|
+
By default, Mongoid History will now track all actions (create, update, and destroy.)
|
8
|
+
Previously, only update actions were tracked by default.
|
9
|
+
|
10
|
+
To preserve the old behavior, please modify your call to `track_history` as follows:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
track_history ...
|
14
|
+
track_create: false,
|
15
|
+
track_destroy: false
|
16
|
+
```
|
17
|
+
|
18
|
+
See [#207](https://github.com/mongoid/mongoid-history/pull/207) for more information.
|
19
|
+
|
20
|
+
### Upgrading to 0.7.0
|
21
|
+
|
22
|
+
#### Remove history track when create, update or destroy raises an error
|
23
|
+
|
24
|
+
When an error is raised in a call to create, update or destroy a tracked model, any history track
|
25
|
+
created before the call will now be deleted. In the past this was a problem for associations marked
|
26
|
+
`dependent: :restrict`.
|
27
|
+
|
28
|
+
See [#202](https://github.com/mongoid/mongoid-history/pull/202) for more information.
|
29
|
+
|
30
|
+
# Main Changes / Upgrading Notes
|
31
|
+
|
32
|
+
See [#189](https://github.com/mongoid/mongoid-history/pull/189) for more information.
|
33
|
+
|
34
|
+
* Currently, the `:all` option behaves identically to `:fields`. Future versions will track all fields and relations of trackable class when using `:all`.
|
35
|
+
|
36
|
+
### Upgrading to 0.4.1
|
37
|
+
|
38
|
+
#### Migrate Userstamp
|
39
|
+
|
40
|
+
`Mongoid::History` no longer supports the userstamp natively. To track the User in the application who created the HistoryTracker, add the [Mongoid::Userstamp gem](https://github.com/tbpro/mongoid_userstamp) to your HistoryTracker class.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
class MyHistoryTracker
|
44
|
+
include Mongoid::History::Tracker
|
45
|
+
include Mongoid::Userstamp
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Rename the field.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
MyHistoryTracker.all.rename(modifier_id: :created_by)
|
53
|
+
```
|
@@ -1,72 +1,72 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module History
|
3
|
-
module Attributes
|
4
|
-
class Base
|
5
|
-
attr_reader :trackable
|
6
|
-
|
7
|
-
def initialize(trackable)
|
8
|
-
@trackable = trackable
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def trackable_class
|
14
|
-
@trackable_class ||= trackable.class
|
15
|
-
end
|
16
|
-
|
17
|
-
def aliased_fields
|
18
|
-
@aliased_fields ||= trackable_class.aliased_fields
|
19
|
-
end
|
20
|
-
|
21
|
-
def changes_method
|
22
|
-
trackable_class.history_trackable_options[:changes_method]
|
23
|
-
end
|
24
|
-
|
25
|
-
def changes
|
26
|
-
trackable.send(changes_method)
|
27
|
-
end
|
28
|
-
|
29
|
-
def format_field(field, value)
|
30
|
-
format_value(value, trackable_class.field_format(field))
|
31
|
-
end
|
32
|
-
|
33
|
-
def format_embeds_one_relation(rel, obj)
|
34
|
-
rel = trackable_class.database_field_name(rel)
|
35
|
-
relation_class = trackable_class.relation_class_of(rel)
|
36
|
-
permitted_attrs = trackable_class.tracked_embeds_one_attributes(rel)
|
37
|
-
formats = trackable_class.field_format(rel)
|
38
|
-
format_relation(relation_class, obj, permitted_attrs, formats)
|
39
|
-
end
|
40
|
-
|
41
|
-
def format_embeds_many_relation(rel, obj)
|
42
|
-
rel = trackable_class.database_field_name(rel)
|
43
|
-
relation_class = trackable_class.relation_class_of(rel)
|
44
|
-
permitted_attrs = trackable_class.tracked_embeds_many_attributes(rel)
|
45
|
-
formats = trackable_class.field_format(rel)
|
46
|
-
format_relation(relation_class, obj, permitted_attrs, formats)
|
47
|
-
end
|
48
|
-
|
49
|
-
def format_relation(relation_class, obj, permitted_attrs, formats)
|
50
|
-
obj.inject({}) do |m, field_value|
|
51
|
-
field = relation_class.database_field_name(field_value.first)
|
52
|
-
next m unless permitted_attrs.include?(field)
|
53
|
-
|
54
|
-
value = field_value.last
|
55
|
-
value = format_value(field_value.last, formats[field]) if formats.class == Hash
|
56
|
-
m.merge(field => value)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def format_value(value, format)
|
61
|
-
if format.class == String
|
62
|
-
format % value
|
63
|
-
elsif format.respond_to?(:call)
|
64
|
-
format.call(value)
|
65
|
-
else
|
66
|
-
value
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
1
|
+
module Mongoid
|
2
|
+
module History
|
3
|
+
module Attributes
|
4
|
+
class Base
|
5
|
+
attr_reader :trackable
|
6
|
+
|
7
|
+
def initialize(trackable)
|
8
|
+
@trackable = trackable
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def trackable_class
|
14
|
+
@trackable_class ||= trackable.class
|
15
|
+
end
|
16
|
+
|
17
|
+
def aliased_fields
|
18
|
+
@aliased_fields ||= trackable_class.aliased_fields
|
19
|
+
end
|
20
|
+
|
21
|
+
def changes_method
|
22
|
+
trackable_class.history_trackable_options[:changes_method]
|
23
|
+
end
|
24
|
+
|
25
|
+
def changes
|
26
|
+
trackable.send(changes_method)
|
27
|
+
end
|
28
|
+
|
29
|
+
def format_field(field, value)
|
30
|
+
format_value(value, trackable_class.field_format(field))
|
31
|
+
end
|
32
|
+
|
33
|
+
def format_embeds_one_relation(rel, obj)
|
34
|
+
rel = trackable_class.database_field_name(rel)
|
35
|
+
relation_class = trackable_class.relation_class_of(rel)
|
36
|
+
permitted_attrs = trackable_class.tracked_embeds_one_attributes(rel)
|
37
|
+
formats = trackable_class.field_format(rel)
|
38
|
+
format_relation(relation_class, obj, permitted_attrs, formats)
|
39
|
+
end
|
40
|
+
|
41
|
+
def format_embeds_many_relation(rel, obj)
|
42
|
+
rel = trackable_class.database_field_name(rel)
|
43
|
+
relation_class = trackable_class.relation_class_of(rel)
|
44
|
+
permitted_attrs = trackable_class.tracked_embeds_many_attributes(rel)
|
45
|
+
formats = trackable_class.field_format(rel)
|
46
|
+
format_relation(relation_class, obj, permitted_attrs, formats)
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_relation(relation_class, obj, permitted_attrs, formats)
|
50
|
+
obj.inject({}) do |m, field_value|
|
51
|
+
field = relation_class.database_field_name(field_value.first)
|
52
|
+
next m unless permitted_attrs.include?(field)
|
53
|
+
|
54
|
+
value = field_value.last
|
55
|
+
value = format_value(field_value.last, formats[field]) if formats.class == Hash
|
56
|
+
m.merge(field => value)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def format_value(value, format)
|
61
|
+
if format.class == String
|
62
|
+
format % value
|
63
|
+
elsif format.respond_to?(:call)
|
64
|
+
format.call(value)
|
65
|
+
else
|
66
|
+
value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,45 +1,45 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module History
|
3
|
-
module Attributes
|
4
|
-
class Create < ::Mongoid::History::Attributes::Base
|
5
|
-
def attributes
|
6
|
-
@attributes = {}
|
7
|
-
changes.each do |k, v|
|
8
|
-
next unless trackable_class.tracked_field?(k, :create)
|
9
|
-
@attributes[k] = format_field(k, v)
|
10
|
-
end
|
11
|
-
insert_embeds_one_changes
|
12
|
-
insert_embeds_many_changes
|
13
|
-
@attributes
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def insert_embeds_one_changes
|
19
|
-
trackable_class.tracked_embeds_one.each do |rel|
|
20
|
-
rel_class = trackable_class.relation_class_of(rel)
|
21
|
-
paranoia_field = Mongoid::History.trackable_class_settings(rel_class)[:paranoia_field]
|
22
|
-
paranoia_field = rel_class.aliased_fields.key(paranoia_field) || paranoia_field
|
23
|
-
rel = aliased_fields.key(rel) || rel
|
24
|
-
obj = trackable.send(rel)
|
25
|
-
next if !obj || (obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present?)
|
26
|
-
@attributes[rel] = [nil, format_embeds_one_relation(rel, obj.attributes)]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def insert_embeds_many_changes
|
31
|
-
trackable_class.tracked_embeds_many.each do |rel|
|
32
|
-
rel_class = trackable_class.relation_class_of(rel)
|
33
|
-
paranoia_field = Mongoid::History.trackable_class_settings(rel_class)[:paranoia_field]
|
34
|
-
paranoia_field = rel_class.aliased_fields.key(paranoia_field) || paranoia_field
|
35
|
-
rel = aliased_fields.key(rel) || rel
|
36
|
-
@attributes[rel] = [nil,
|
37
|
-
trackable.send(rel)
|
38
|
-
.reject { |obj| obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present? }
|
39
|
-
.map { |obj| format_embeds_many_relation(rel, obj.attributes) }]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
1
|
+
module Mongoid
|
2
|
+
module History
|
3
|
+
module Attributes
|
4
|
+
class Create < ::Mongoid::History::Attributes::Base
|
5
|
+
def attributes
|
6
|
+
@attributes = {}
|
7
|
+
changes.each do |k, v|
|
8
|
+
next unless trackable_class.tracked_field?(k, :create)
|
9
|
+
@attributes[k] = format_field(k, v)
|
10
|
+
end
|
11
|
+
insert_embeds_one_changes
|
12
|
+
insert_embeds_many_changes
|
13
|
+
@attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def insert_embeds_one_changes
|
19
|
+
trackable_class.tracked_embeds_one.each do |rel|
|
20
|
+
rel_class = trackable_class.relation_class_of(rel)
|
21
|
+
paranoia_field = Mongoid::History.trackable_class_settings(rel_class)[:paranoia_field]
|
22
|
+
paranoia_field = rel_class.aliased_fields.key(paranoia_field) || paranoia_field
|
23
|
+
rel = aliased_fields.key(rel) || rel
|
24
|
+
obj = trackable.send(rel)
|
25
|
+
next if !obj || (obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present?)
|
26
|
+
@attributes[rel] = [nil, format_embeds_one_relation(rel, obj.attributes)]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def insert_embeds_many_changes
|
31
|
+
trackable_class.tracked_embeds_many.each do |rel|
|
32
|
+
rel_class = trackable_class.relation_class_of(rel)
|
33
|
+
paranoia_field = Mongoid::History.trackable_class_settings(rel_class)[:paranoia_field]
|
34
|
+
paranoia_field = rel_class.aliased_fields.key(paranoia_field) || paranoia_field
|
35
|
+
rel = aliased_fields.key(rel) || rel
|
36
|
+
@attributes[rel] = [nil,
|
37
|
+
trackable.send(rel)
|
38
|
+
.reject { |obj| obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present? }
|
39
|
+
.map { |obj| format_embeds_many_relation(rel, obj.attributes) }]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module History
|
3
|
-
module Attributes
|
4
|
-
class Destroy < ::Mongoid::History::Attributes::Base
|
5
|
-
def attributes
|
6
|
-
@attributes = {}
|
7
|
-
trackable.attributes.each { |k, v| @attributes[k] = [format_field(k, v), nil] if trackable_class.tracked_field?(k, :destroy) }
|
8
|
-
insert_embeds_one_changes
|
9
|
-
insert_embeds_many_changes
|
10
|
-
@attributes
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def insert_embeds_one_changes
|
16
|
-
trackable_class.tracked_embeds_one
|
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
|
-
end
|
23
|
-
|
24
|
-
def insert_embeds_many_changes
|
25
|
-
trackable_class.tracked_embeds_many
|
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
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
module Mongoid
|
2
|
+
module History
|
3
|
+
module Attributes
|
4
|
+
class Destroy < ::Mongoid::History::Attributes::Base
|
5
|
+
def attributes
|
6
|
+
@attributes = {}
|
7
|
+
trackable.attributes.each { |k, v| @attributes[k] = [format_field(k, v), nil] if trackable_class.tracked_field?(k, :destroy) }
|
8
|
+
insert_embeds_one_changes
|
9
|
+
insert_embeds_many_changes
|
10
|
+
@attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def insert_embeds_one_changes
|
16
|
+
trackable_class.tracked_embeds_one
|
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
|
+
end
|
23
|
+
|
24
|
+
def insert_embeds_many_changes
|
25
|
+
trackable_class.tracked_embeds_many
|
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
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|