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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32a2a6bf326937407f72ee7eec95c06bbe6f19b0
4
- data.tar.gz: bf4838d2972bdbc039e0ae2027be5518dae82204
3
+ metadata.gz: 1d3aef06ac0a4db5ed68bbcd26e76267d034333e
4
+ data.tar.gz: 89f5edd82ecff4219fbeb588542e5f988a0fca0f
5
5
  SHA512:
6
- metadata.gz: 14e222f0788fae82653fb7813661cba97821c3349e0177c33916f38ec2153ca53decfbcfb79bfdcb0bbce73b76536abed698ed66ef7fc3f3a1e13898ae0955b4
7
- data.tar.gz: 871f20de14eb3cc5e284a290c231827a74f89db227026a4a8da2a7df61daface01b642aef6f9256a3d722ec66997c8c11faff2f50eb5c2ec620e688a3c5e381e
6
+ metadata.gz: 2e0751f17fdf47bd3b9d01606017206b47429797ece3c0b98860c3b369e6f7f1dd9df59981361c5db322778d77879d7827f93208966ff1b5095fa840e223b870
7
+ data.tar.gz: c907128dfaeaf4eaa6d5251bd0aca0c563c07a4ef31f8539453ad77638b8b95483543d9f087661b01535203294a0df45e65ecccbf04adf6d022673581e18d173
@@ -4,27 +4,37 @@ module Logga
4
4
 
5
5
  class_methods do
6
6
  def add_log_entries_for(*actions)
7
- around_update :log_model_changes if actions.include?(:update)
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) if yield
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 log_field_changes(changes)
17
- changes.each { |field, values| log_field_change(field, *values) }
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 log_field_change(field, old_value, new_value)
21
- author_data = Hash(try(:author))
22
- self.log_entries.create(
23
- body: "changed #{field} from #{old_value} to #{new_value}",
24
- author_id: author_data[:id],
25
- author_tupe: author_data[:type],
26
- author_name: author_data[:name]
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
@@ -1,3 +1,3 @@
1
1
  module Logga
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
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-13 00:00:00.000000000 Z
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler