logga 0.1.4 → 0.2.0
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 +12 -11
- 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: 13c49b4d4a45c966a1e329a5e4fbecbf1d0766d2
|
4
|
+
data.tar.gz: 8b828e895133ea716983708adf4c7a763c04519b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39e077a00926918f3a62787ceb86ece91676aec46d0bc89052a4e15f77fb02a3a19926fb7d2bd97c4b618b39b2fb784d72449b57f9b06b5703b0e98c1eb4ec71
|
7
|
+
data.tar.gz: 8e991e17f2b07de6ed7da2e212c60a3c3c75c813d360d3c9063010847ce2957510b825300a65fc2fe57235e793688bbab246297b462c4c67c800828a3cc2e5ae
|
data/lib/logga/active_record.rb
CHANGED
@@ -3,37 +3,38 @@ module Logga
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
class_methods do
|
6
|
-
def add_log_entries_for(*actions)
|
6
|
+
def add_log_entries_for(*actions, to: :self)
|
7
7
|
after_create :log_model_creation if actions.include?(:create)
|
8
8
|
after_update :log_model_changes if actions.include?(:update)
|
9
|
+
define_method(:log_receiver) { to == :self ? self : send(to) }
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
def log_model_creation
|
13
14
|
body = "#{self.class} created"
|
14
|
-
|
15
|
+
log_receiver.log_entries.create(author_data.merge(body: body))
|
15
16
|
end
|
16
17
|
|
17
18
|
def log_model_changes
|
18
19
|
field_changes = changes.except(:created_at, :updated_at, :log)
|
19
|
-
log_field_changes(field_changes
|
20
|
+
log_field_changes(field_changes)
|
20
21
|
end
|
21
22
|
|
22
|
-
def log_field_changes(changes
|
23
|
-
changes.each { |field, values| log_field_change(field, *values
|
23
|
+
def log_field_changes(changes)
|
24
|
+
changes.each { |field, values| log_field_change(field, *values) }
|
24
25
|
end
|
25
26
|
|
26
|
-
def log_field_change(field, old_value, new_value
|
27
|
+
def log_field_change(field, old_value, new_value)
|
27
28
|
body = "changed #{field} from #{old_value} to #{new_value}"
|
28
|
-
|
29
|
+
log_receiver.log_entries.create(author_data.merge(body: body))
|
29
30
|
end
|
30
31
|
|
31
32
|
def author_data
|
32
|
-
data = Hash(author).with_indifferent_access
|
33
|
+
data = Hash(log_receiver.author).with_indifferent_access
|
33
34
|
{
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
author_id: data[:id],
|
36
|
+
author_type: data[:type],
|
37
|
+
author_name: data[:name]
|
37
38
|
}
|
38
39
|
end
|
39
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.
|
4
|
+
version: 0.2.0
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|