logga 0.4.7 → 0.5.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 +9 -5
- data/lib/logga/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90ad8c80a8ecf201d47feabd056cf8db08a42d92
|
4
|
+
data.tar.gz: c6fb3e1abb33d4bf16ebe22e0036314b6d2d9773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2702013ce3ab3e0a7f8dd5e85b0123514d8f2bff78e24481b2eef5af4654fce2adc83f1ff64dc5f38fd02a344ef46460325696670bed68e03491026802104a4a
|
7
|
+
data.tar.gz: c7204f2cee01d6afd335c6cabc702b06eb034f01706feb918be4cd9454c860c6a86ae43f2e9c03bed84aadb8fc8df472476bd0c4470c71ca001e20ba0a197510
|
data/lib/logga/active_record.rb
CHANGED
@@ -6,17 +6,20 @@ module Logga
|
|
6
6
|
EXCLUDED_KEYS_SUFFIXES = [:_id, :_filenames]
|
7
7
|
|
8
8
|
included do
|
9
|
-
class_attribute :log_fields,
|
10
|
-
|
9
|
+
class_attribute :log_fields, instance_writer: false
|
10
|
+
class_attribute :excluded_fields, instance_writer: false
|
11
|
+
self.log_fields = {}
|
12
|
+
self.excluded_fields = {}
|
11
13
|
end
|
12
14
|
|
13
15
|
class_methods do
|
14
|
-
def add_log_entries_for(*actions, to: :self, fields: {}
|
16
|
+
def add_log_entries_for(*actions, to: :self, fields: {}, exclude_fields: []
|
15
17
|
after_create :log_model_creation if actions.include?(:create)
|
16
18
|
after_destroy :log_model_deletion if actions.include?(:delete)
|
17
19
|
after_update :log_model_changes if actions.include?(:update)
|
18
20
|
define_method(:log_receiver) { to == :self ? self : send(to) }
|
19
|
-
self.log_fields
|
21
|
+
self.log_fields = fields
|
22
|
+
self.excluded_fields = Array(exclude_fields)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
@@ -34,7 +37,8 @@ module Logga
|
|
34
37
|
|
35
38
|
def log_model_changes
|
36
39
|
field_changes = changes.reject do |k, _|
|
37
|
-
|
40
|
+
excluded_fields.include?(k.to_sym) ||
|
41
|
+
EXCLUDED_KEYS.include?(k.to_sym) ||
|
38
42
|
EXCLUDED_KEYS_SUFFIXES.any? { |suffix| k.to_s.end_with?(suffix.to_s) }
|
39
43
|
end
|
40
44
|
log_field_changes(field_changes)
|
data/lib/logga/version.rb
CHANGED