logga 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logga/active_record.rb +23 -13
- data/lib/logga/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d3aef06ac0a4db5ed68bbcd26e76267d034333e
|
4
|
+
data.tar.gz: 89f5edd82ecff4219fbeb588542e5f988a0fca0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0751f17fdf47bd3b9d01606017206b47429797ece3c0b98860c3b369e6f7f1dd9df59981361c5db322778d77879d7827f93208966ff1b5095fa840e223b870
|
7
|
+
data.tar.gz: c907128dfaeaf4eaa6d5251bd0aca0c563c07a4ef31f8539453ad77638b8b95483543d9f087661b01535203294a0df45e65ecccbf04adf6d022673581e18d173
|
data/lib/logga/active_record.rb
CHANGED
@@ -4,27 +4,37 @@ module Logga
|
|
4
4
|
|
5
5
|
class_methods do
|
6
6
|
def add_log_entries_for(*actions)
|
7
|
-
|
7
|
+
after_create :log_model_creation if actions.include?(:create)
|
8
|
+
after_update :log_model_changes if actions.include?(:update)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
12
|
+
def log_model_creation
|
13
|
+
body = "#{self.class} created"
|
14
|
+
self.log_entries.create(author_data.merge(body: body))
|
15
|
+
end
|
16
|
+
|
11
17
|
def log_model_changes
|
12
|
-
field_changes = changes
|
13
|
-
log_field_changes(field_changes)
|
18
|
+
field_changes = changes.except(:created_at, :updated_at, :log)
|
19
|
+
log_field_changes(field_changes, author)
|
20
|
+
end
|
21
|
+
|
22
|
+
def log_field_changes(changes, author)
|
23
|
+
changes.each { |field, values| log_field_change(field, *values, author) }
|
14
24
|
end
|
15
25
|
|
16
|
-
def
|
17
|
-
|
26
|
+
def log_field_change(field, old_value, new_value, author)
|
27
|
+
body = "changed #{field} from #{old_value} to #{new_value}"
|
28
|
+
self.log_entries.create(author_data.merge(body: body))
|
18
29
|
end
|
19
30
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
)
|
31
|
+
def author_data
|
32
|
+
data = Hash(author).with_indifferent_access
|
33
|
+
{
|
34
|
+
author_id: data[:id],
|
35
|
+
author_type: data[:type],
|
36
|
+
author_name: data[:name]
|
37
|
+
}
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
data/lib/logga/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Chinery, Rob Hesketh, Lorenzo Tello
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|