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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2b4685fe6f3a1ebf00cfe984839b901b9400bde
4
- data.tar.gz: 62f964bc27049e101262e90d3d4e9a497e0bc733
3
+ metadata.gz: 9d43f622f0a3a93ff1d9ebabdc1991ec4264457b
4
+ data.tar.gz: b335aabbe73612f869fab754f0d4c8f4e4ecf5ca
5
5
  SHA512:
6
- metadata.gz: d768e0538660f31428f41a69d0aec6bc5fd53b67a4149b7bae0d00d8226313d96b013c29673b7bfc7cc1551afbd0bf60deb30c9cc36f1068434bc99af0e6660a
7
- data.tar.gz: aa4901c3829d000e346c4dde4d7be4d4afbeba0c1918094fedecf8cf8952dd93b7e3e6b8a608668d1be5cc72d49bce48307dd49fe50f41dc017845c10f5573c2
6
+ metadata.gz: 1380ada33016abd3639f1c7dcac1b40f00fd75dbb3383609207a33a26260a3c5b80086df1b5f69866a046f4a5ca1ea3cdd222c67f82f5673388ea380b86a78c7
7
+ data.tar.gz: 7de598ea672562c2a130be403c342473c391694f673894fadb36bdfd4543db6e8d889cf8e9a755a2d32f222f022551f94f50b9dff402ff7ca2ffa68568bd111e
@@ -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 :log_model_creation if actions.include?(:create)
16
- after_update :log_model_changes if actions.include?(:update)
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
@@ -1,3 +1,3 @@
1
1
  module Logga
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Chinery, Rob Hesketh, Lorenzo Tello