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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d3aef06ac0a4db5ed68bbcd26e76267d034333e
4
- data.tar.gz: 89f5edd82ecff4219fbeb588542e5f988a0fca0f
3
+ metadata.gz: 13c49b4d4a45c966a1e329a5e4fbecbf1d0766d2
4
+ data.tar.gz: 8b828e895133ea716983708adf4c7a763c04519b
5
5
  SHA512:
6
- metadata.gz: 2e0751f17fdf47bd3b9d01606017206b47429797ece3c0b98860c3b369e6f7f1dd9df59981361c5db322778d77879d7827f93208966ff1b5095fa840e223b870
7
- data.tar.gz: c907128dfaeaf4eaa6d5251bd0aca0c563c07a4ef31f8539453ad77638b8b95483543d9f087661b01535203294a0df45e65ecccbf04adf6d022673581e18d173
6
+ metadata.gz: 39e077a00926918f3a62787ceb86ece91676aec46d0bc89052a4e15f77fb02a3a19926fb7d2bd97c4b618b39b2fb784d72449b57f9b06b5703b0e98c1eb4ec71
7
+ data.tar.gz: 8e991e17f2b07de6ed7da2e212c60a3c3c75c813d360d3c9063010847ce2957510b825300a65fc2fe57235e793688bbab246297b462c4c67c800828a3cc2e5ae
@@ -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
- self.log_entries.create(author_data.merge(body: body))
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, author)
20
+ log_field_changes(field_changes)
20
21
  end
21
22
 
22
- def log_field_changes(changes, author)
23
- changes.each { |field, values| log_field_change(field, *values, author) }
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, author)
27
+ def log_field_change(field, old_value, new_value)
27
28
  body = "changed #{field} from #{old_value} to #{new_value}"
28
- self.log_entries.create(author_data.merge(body: body))
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
- author_id: data[:id],
35
- author_type: data[:type],
36
- author_name: data[:name]
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
@@ -1,3 +1,3 @@
1
1
  module Logga
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
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.4
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-14 00:00:00.000000000 Z
11
+ date: 2017-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler