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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff3af4d1f95aaf1d746dbaa69f13499aeeddacd82617903a7c39cab41ccb19f1
4
- data.tar.gz: 8aa212d93cc1797ffa0d00311f61cb529bb7a43b0fcca4398663c1ead4d538a6
3
+ metadata.gz: 718afad5f797fe8acf640b0541086f99033e4457707a5fb5daa3b4505adf8d8d
4
+ data.tar.gz: 92ba729bc96163933fa532d5d66b35ceeef4b3b85f43a76cd47c0e83518af6b1
5
5
  SHA512:
6
- metadata.gz: b1b9ccdb25f8bd5de48aa18ead6b7fc12f65fe40eea47cdd9ffe7594c86be327a860614452fe663e1613c46a634472ff74a235fae16d35b3e00dbb7ad9e9d0a7
7
- data.tar.gz: d317c56de028253096e9e97febe256688e6b6ea0f4bea53d7aff41451fc1b66fb48d2cb0415ba9c3aa6e70fa35f6edf3f3bf11ad797adf75cd1765aa871a285f
6
+ metadata.gz: 346b36e40c17a2bb6836c304f868eaadf92db5574cc13fd3aaaa2dd9243a4f689e582e6ed4941346ddb35406ca28351afd2e4fee928764a7d224cb180fbd7fc0
7
+ data.tar.gz: 0c88dbb79f64014e8f62439d48df1fadb16e1742f01573fc132b989012b14185c32b6f8f2a9302c2e4f5a5b2b7ca05d20258bc934ee25858427c4e5aeff34d6d
@@ -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.metadata_name.to_s : nil
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 ||= Mongoid::AuditLog::EmbeddedChanges.new(model).all
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
@@ -44,7 +44,7 @@ module Mongoid
44
44
  nil
45
45
  else
46
46
  klass = Mongoid::AuditLog.modifier_class_name.constantize
47
- klass.find(modifier_id) rescue nil
47
+ klass.find(modifier_id)
48
48
  end
49
49
  end
50
50
 
@@ -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.many?
57
+ if metadata.is_a?(Association::Embedded::EmbedsMany)
58
58
  relation.build
59
59
  elsif relation.present?
60
60
  raise DuplicateError
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module AuditLog
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -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", [">= 6.0.x", "< 7.0"]
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.5.1
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: 2020-10-15 00:00:00.000000000 Z
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.3
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