logga 0.3.2 → 0.4.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 +17 -3
- 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: 9d43f622f0a3a93ff1d9ebabdc1991ec4264457b
|
4
|
+
data.tar.gz: b335aabbe73612f869fab754f0d4c8f4e4ecf5ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1380ada33016abd3639f1c7dcac1b40f00fd75dbb3383609207a33a26260a3c5b80086df1b5f69866a046f4a5ca1ea3cdd222c67f82f5673388ea380b86a78c7
|
7
|
+
data.tar.gz: 7de598ea672562c2a130be403c342473c391694f673894fadb36bdfd4543db6e8d889cf8e9a755a2d32f222f022551f94f50b9dff402ff7ca2ffa68568bd111e
|
data/lib/logga/active_record.rb
CHANGED
@@ -2,7 +2,7 @@ module Logga
|
|
2
2
|
module ActiveRecord
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
EXCLUDED_KEYS = [:created_at, :updated_at, :log, :sent_photos_chaser_email, :sent_after_sales_emails]
|
5
|
+
EXCLUDED_KEYS = [:created_at, :deleted_at, :updated_at, :log, :sent_photos_chaser_email, :sent_after_sales_emails]
|
6
6
|
EXCLUDED_KEYS_SUFFIXES = [:_id, :_filenames]
|
7
7
|
|
8
8
|
included do
|
@@ -12,8 +12,9 @@ module Logga
|
|
12
12
|
|
13
13
|
class_methods do
|
14
14
|
def add_log_entries_for(*actions, to: :self, fields: {})
|
15
|
-
after_create
|
16
|
-
|
15
|
+
after_create :log_model_creation if actions.include?(:create)
|
16
|
+
after_destroy :log_model_deletion if actions.include?(:delete)
|
17
|
+
after_update :log_model_changes if actions.include?(:update)
|
17
18
|
define_method(:log_receiver) { to == :self ? self : send(to) }
|
18
19
|
self.log_fields = fields
|
19
20
|
end
|
@@ -25,6 +26,12 @@ module Logga
|
|
25
26
|
log_receiver.log_entries.create(author_data.merge(body: body))
|
26
27
|
end
|
27
28
|
|
29
|
+
def log_model_deletion
|
30
|
+
body_generator = ->(record) {default_deletion_log_body(record)}
|
31
|
+
body = log_fields.fetch(:deleted_at, body_generator).call(self)
|
32
|
+
log_receiver.log_entries.create(author_data.merge(body: body))
|
33
|
+
end
|
34
|
+
|
28
35
|
def log_model_changes
|
29
36
|
field_changes = changes.reject do |k, _|
|
30
37
|
EXCLUDED_KEYS.include?(k.to_sym) ||
|
@@ -62,5 +69,12 @@ module Logga
|
|
62
69
|
def default_change_log_body(record, field, old_value, new_value)
|
63
70
|
"#{record.class.name.demodulize.titleize} #{field} set to #{new_value}"
|
64
71
|
end
|
72
|
+
|
73
|
+
def default_deletion_log_body(record)
|
74
|
+
[
|
75
|
+
"#{record.class.name.demodulize} removed",
|
76
|
+
("(#{record.name})" if record.try(:name))
|
77
|
+
].compact.join(' ')
|
78
|
+
end
|
65
79
|
end
|
66
80
|
end
|
data/lib/logga/version.rb
CHANGED