activeaudit 0.1.4 → 0.1.5
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.
- data/README.md +1 -0
- data/lib/active_audit/logger.rb +19 -25
- metadata +4 -4
data/README.md
CHANGED
@@ -4,6 +4,7 @@ Audit support for Active Record
|
|
4
4
|
|
5
5
|
[](https://travis-ci.org/maintux/activeaudit)
|
6
6
|
[](https://codeclimate.com/github/maintux/activeaudit)
|
7
|
+
[](https://gemnasium.com/maintux/activeaudit)
|
7
8
|
|
8
9
|
## Install
|
9
10
|
|
data/lib/active_audit/logger.rb
CHANGED
@@ -14,6 +14,7 @@ module ActiveAudit
|
|
14
14
|
before_destroy :log_activity_on_destroy
|
15
15
|
|
16
16
|
attr_accessible :audit_user_id
|
17
|
+
attr_accessible :audit_extras
|
17
18
|
attr_accessor :audit_user_id
|
18
19
|
attr_accessor :audit_extras
|
19
20
|
|
@@ -25,24 +26,24 @@ module ActiveAudit
|
|
25
26
|
self.loggable_events.merge! event
|
26
27
|
end
|
27
28
|
|
29
|
+
def log_event(activity)
|
30
|
+
ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: activity, extras: audit_extras
|
31
|
+
end
|
32
|
+
private :log_event
|
33
|
+
|
28
34
|
def log_activity_on_create
|
29
35
|
self.class.loggable_events.each do |k,v|
|
30
36
|
next unless k.eql?(:create)
|
31
37
|
if v.eql?(true)
|
32
|
-
|
38
|
+
log_event k.to_s
|
33
39
|
elsif v.is_a?(Array)
|
34
|
-
log_event = false
|
35
40
|
v.each do |field|
|
36
|
-
if field.is_a?(Hash)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
log_event and break if self.send(field.to_s)
|
41
|
+
if field.is_a?(Hash) and self.send(field.keys.first).eql?(field.values.first)
|
42
|
+
log_event(k.to_s) and break
|
43
|
+
elsif field.is_a?(Symbol) and self.send(field.to_s)
|
44
|
+
log_event(k.to_s) and break
|
41
45
|
end
|
42
46
|
end
|
43
|
-
if log_event
|
44
|
-
ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s, extras: audit_extras
|
45
|
-
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -51,20 +52,13 @@ module ActiveAudit
|
|
51
52
|
self.class.loggable_events.each do |k,v|
|
52
53
|
next if [:create,:destroy].include?(k)
|
53
54
|
if k.eql?(:update) and v.eql?(true)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
log_event = true and break if self.send("#{key}_changed?") and self.send(key.to_s).eql?(value)
|
62
|
-
elsif field.is_a?(Symbol)
|
63
|
-
log_event = true and break if self.send("#{field}_changed?")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
if log_event
|
67
|
-
ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s, extras: audit_extras
|
55
|
+
log_event k.to_s
|
56
|
+
elsif v.is_a?(Array)
|
57
|
+
v.each do |field|
|
58
|
+
if field.is_a?(Hash) and self.send("#{field.keys.first}_changed?") and self.send(field.keys.first).eql?(field.values.first)
|
59
|
+
log_event(k.to_s) and break
|
60
|
+
elsif field.is_a?(Symbol) and self.send("#{field}_changed?")
|
61
|
+
log_event(k.to_s) and break
|
68
62
|
end
|
69
63
|
end
|
70
64
|
end
|
@@ -74,7 +68,7 @@ module ActiveAudit
|
|
74
68
|
def log_activity_on_destroy
|
75
69
|
self.class.loggable_events.each do |k,v|
|
76
70
|
next unless k.eql?(:destroy)
|
77
|
-
|
71
|
+
log_event k.to_s
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeaudit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 4.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 4.0.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bundler
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
segments:
|
160
160
|
- 0
|
161
|
-
hash:
|
161
|
+
hash: 1684660491457008087
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
none: false
|
164
164
|
requirements:
|