mongoid-audit_log 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid/audit_log.rb +1 -2
- data/lib/mongoid/audit_log/changes.rb +11 -1
- data/lib/mongoid/audit_log/entry.rb +1 -1
- data/lib/mongoid/audit_log/restore.rb +1 -1
- data/lib/mongoid/audit_log/version.rb +1 -1
- data/mongoid-audit_log.gemspec +1 -1
- data/spec/mongoid/audit_log/entry_spec.rb +0 -5
- metadata +3 -10
- data/lib/mongoid/audit_log/embedded_changes.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 718afad5f797fe8acf640b0541086f99033e4457707a5fb5daa3b4505adf8d8d
|
4
|
+
data.tar.gz: 92ba729bc96163933fa532d5d66b35ceeef4b3b85f43a76cd47c0e83518af6b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 346b36e40c17a2bb6836c304f868eaadf92db5574cc13fd3aaaa2dd9243a4f689e582e6ed4941346ddb35406ca28351afd2e4fee928764a7d224cb180fbd7fc0
|
7
|
+
data.tar.gz: 0c88dbb79f64014e8f62439d48df1fadb16e1742f01573fc132b989012b14185c32b6f8f2a9302c2e4f5a5b2b7ca05d20258bc934ee25858427c4e5aeff34d6d
|
data/lib/mongoid/audit_log.rb
CHANGED
@@ -2,7 +2,6 @@ require "mongoid/audit_log/version"
|
|
2
2
|
require "mongoid/audit_log/config"
|
3
3
|
require "mongoid/audit_log/entry"
|
4
4
|
require "mongoid/audit_log/changes"
|
5
|
-
require "mongoid/audit_log/embedded_changes"
|
6
5
|
require "mongoid/audit_log/restore"
|
7
6
|
|
8
7
|
module Mongoid
|
@@ -83,7 +82,7 @@ module Mongoid
|
|
83
82
|
end
|
84
83
|
|
85
84
|
def traverse_association_chain(node = self, current_relation = nil)
|
86
|
-
relation = node.embedded? ? node.
|
85
|
+
relation = node.embedded? ? node.association_name.to_s : nil
|
87
86
|
list = node._parent ? traverse_association_chain(node._parent, relation) : []
|
88
87
|
list << { class_name: node.class.name, id: node.id, relation: current_relation }
|
89
88
|
list
|
@@ -61,7 +61,17 @@ module Mongoid
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def embedded_changes
|
64
|
-
@embedded_changes ||=
|
64
|
+
@embedded_changes ||= model.embedded_relations.inject({}) do |memo, t|
|
65
|
+
name = t.first
|
66
|
+
embedded = model.send(name)
|
67
|
+
changes = Mongoid::AuditLog::Changes.extract_from(embedded)
|
68
|
+
|
69
|
+
if embedded.present? && changes.present?
|
70
|
+
memo[name] = changes
|
71
|
+
end
|
72
|
+
|
73
|
+
memo
|
74
|
+
end
|
65
75
|
end
|
66
76
|
end
|
67
77
|
end
|
@@ -54,7 +54,7 @@ module Mongoid
|
|
54
54
|
metadata = restored_root.class.reflect_on_association(last_path['relation'])
|
55
55
|
relation = restored_root.send(last_path['relation'])
|
56
56
|
|
57
|
-
if metadata.
|
57
|
+
if metadata.is_a?(Association::Embedded::EmbedsMany)
|
58
58
|
relation.build
|
59
59
|
elsif relation.present?
|
60
60
|
raise DuplicateError
|
data/mongoid-audit_log.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = ">= 1.9.2"
|
22
22
|
spec.required_rubygems_version = ">= 1.3.6"
|
23
23
|
|
24
|
-
spec.add_runtime_dependency "mongoid", [">=
|
24
|
+
spec.add_runtime_dependency "mongoid", [">= 7.0"]
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler"
|
27
27
|
spec.add_development_dependency "rake"
|
@@ -81,11 +81,6 @@ module Mongoid
|
|
81
81
|
entry = Entry.new(:modifier_id => user.id)
|
82
82
|
entry.modifier.should == user
|
83
83
|
end
|
84
|
-
|
85
|
-
it 'can handle a missing modifier' do
|
86
|
-
entry = Entry.new(:modifier_id => 'foo')
|
87
|
-
entry.modifier.should be_nil
|
88
|
-
end
|
89
84
|
end
|
90
85
|
|
91
86
|
describe '#audited' do
|
metadata
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-audit_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Crouse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0.x
|
20
|
-
- - "<"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '7.0'
|
23
20
|
type: :runtime
|
@@ -25,9 +22,6 @@ dependencies:
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 6.0.x
|
30
|
-
- - "<"
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: '7.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
@@ -74,7 +68,6 @@ files:
|
|
74
68
|
- lib/mongoid/audit_log.rb
|
75
69
|
- lib/mongoid/audit_log/changes.rb
|
76
70
|
- lib/mongoid/audit_log/config.rb
|
77
|
-
- lib/mongoid/audit_log/embedded_changes.rb
|
78
71
|
- lib/mongoid/audit_log/entry.rb
|
79
72
|
- lib/mongoid/audit_log/restore.rb
|
80
73
|
- lib/mongoid/audit_log/version.rb
|
@@ -104,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
97
|
- !ruby/object:Gem::Version
|
105
98
|
version: 1.3.6
|
106
99
|
requirements: []
|
107
|
-
rubygems_version: 3.0.
|
100
|
+
rubygems_version: 3.0.6
|
108
101
|
signing_key:
|
109
102
|
specification_version: 4
|
110
103
|
summary: No fancy versioning, undo, redo, etc. Just saves changes to Mongoid models
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module AuditLog
|
3
|
-
class EmbeddedChanges
|
4
|
-
attr_reader :model
|
5
|
-
|
6
|
-
def initialize(model)
|
7
|
-
@model = model
|
8
|
-
end
|
9
|
-
|
10
|
-
def relations
|
11
|
-
model.relations.inject({}) do |memo, t|
|
12
|
-
name, relation = *t
|
13
|
-
memo[name] = relation if relation.embedded?
|
14
|
-
memo
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def all
|
19
|
-
@all ||= relations.inject({}) do |memo, t|
|
20
|
-
name = t.first
|
21
|
-
embedded = model.send(name)
|
22
|
-
changes = Mongoid::AuditLog::Changes.extract_from(embedded)
|
23
|
-
|
24
|
-
if embedded.present? && changes.present?
|
25
|
-
memo[name] = changes
|
26
|
-
end
|
27
|
-
|
28
|
-
memo
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|