effective_logging 2.0.3 → 2.0.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: 1f13ff153b87e251c687b2fbd6fe49dc870050c0
4
- data.tar.gz: bbee752de6d570e21276612e9a14d97448671640
3
+ metadata.gz: 731f331a434fe08296dac04c2b5220521f06163c
4
+ data.tar.gz: b50f15e84035e9dc56bcbb5644ad8893e9673cd6
5
5
  SHA512:
6
- metadata.gz: 5c805494dba913dd2bd10dd047e10b047f22e7c79164419cfaa76ab1ba22e51191b854a7681bc6129061e41f0804615b890e115759cfd703c749c091e1929b7b
7
- data.tar.gz: 3aa1ec9ddf7cfa73e0de6dca4fea9bbf53fa35c3a057ca0fc84c0c0faad950fd6f64340b5df89780db0b6d6f0a580b6b62dc4ee6fd4062fb6c45193239e5bf96
6
+ metadata.gz: c0114fdb00a7a7abe49218a689ca57c921a21a833965537c438e1074baf1bc654d8fff6f48f3117737093fddd69c07c2f4f4fcfffd463e9cf38a2c1c2e8d3792
7
+ data.tar.gz: 67725f27c6d721f0c6f029d1c6ff2552cc1b7e83c1779323240208833f1d8ad9ffc86ed9ac2edd82cb1079ab5d399ae28ac807e5bb95d6e9d90dc09885aeb45d
data/README.md CHANGED
@@ -225,6 +225,14 @@ Each changed attribute will have its before and after values logged to form an a
225
225
 
226
226
  And on each create / destroy / update, a full dump of all current attributes is saved, forming an audit log.
227
227
 
228
+ If this ends up hammering your database, you can skip logging the associations by using `except` or `include_associated: false`
229
+
230
+ ```ruby
231
+ class Post < ActiveRecord::Base
232
+ log_changes include_associated: false
233
+ end
234
+ ```
235
+
228
236
  There is some initial support for passing `only`, `except`, and `additionally` to the mixin to customize what attributes are saved.
229
237
 
230
238
  Define your model with `log_changes additionally: [:method1, :method2]` to also _always_ log the value of that method. Even if it's unchanged.
@@ -9,6 +9,10 @@ module ActsAsLoggable
9
9
  raise ArgumentError.new('invalid arguments passed to (effective_logging) log_changes. Example usage: log_changes except: [:created_at]')
10
10
  end
11
11
 
12
+ if (unknown = (@acts_as_loggable_options.keys - [:only, :except, :additionally, :include_associated])).present?
13
+ raise ArgumentError.new("unknown keyword: #{unknown.join(', ')}")
14
+ end
15
+
12
16
  include ::ActsAsLoggable
13
17
  end
14
18
  end
@@ -47,9 +51,14 @@ module ActsAsLoggable
47
51
  log_changes_options = {
48
52
  only: Array(@acts_as_loggable_options[:only]).map { |attribute| attribute.to_s },
49
53
  except: Array(@acts_as_loggable_options[:except]).map { |attribute| attribute.to_s },
50
- additionally: Array(@acts_as_loggable_options[:additionally]).map { |attribute| attribute.to_s }
54
+ additionally: Array(@acts_as_loggable_options[:additionally]).map { |attribute| attribute.to_s },
55
+ include_associated: @acts_as_loggable_options.fetch(:include_associated, true)
51
56
  }
52
57
 
58
+ if name == 'User'
59
+ log_changes_options[:except] += %w(sign_in_count current_sign_in_at current_sign_in_ip last_sign_in_at last_sign_in_ip encrypted_password remember_created_at reset_password_token invitation_sent_at invitation_created_at invitation_token)
60
+ end
61
+
53
62
  self.send(:define_method, :log_changes_options) { log_changes_options }
54
63
  end
55
64
 
@@ -1,6 +1,6 @@
1
1
  module EffectiveLogging
2
2
  class ActiveRecordLogger
3
- attr_accessor :object, :resource, :logger, :depth, :options
3
+ attr_accessor :object, :resource, :logger, :depth, :include_associated, :options
4
4
 
5
5
  BLANK = "''"
6
6
 
@@ -13,6 +13,7 @@ module EffectiveLogging
13
13
 
14
14
  @logger = options.delete(:logger) || object
15
15
  @depth = options.delete(:depth) || 0
16
+ @include_associated = options.fetch(:include_associated, true)
16
17
  @options = options
17
18
 
18
19
  raise ArgumentError.new('logger must respond to logged_changes') unless @logger.respond_to?(:logged_changes)
@@ -27,24 +28,25 @@ module EffectiveLogging
27
28
  else
28
29
  changed!
29
30
  end
30
- log_nested_resources!
31
+
32
+ log_nested_resources! if include_associated
31
33
 
32
34
  @logged
33
35
  end
34
36
 
35
37
  # before_destroy
36
38
  def destroyed!
37
- log('Deleted', details: applicable(resource.instance_attributes))
39
+ log('Deleted')
38
40
  end
39
41
 
40
42
  # after_commit
41
43
  def created!
42
- log('Created', details: applicable(resource.instance_attributes))
44
+ log('Created', details: applicable(resource.instance_attributes(include_associated: include_associated)))
43
45
  end
44
46
 
45
47
  # after_commit
46
48
  def updated!
47
- log('Updated', details: applicable(resource.instance_attributes))
49
+ log('Updated', details: applicable(resource.instance_attributes(include_associated: include_associated)))
48
50
  end
49
51
 
50
52
  private
@@ -73,7 +75,8 @@ module EffectiveLogging
73
75
  title = association.name.to_s.singularize.titleize
74
76
 
75
77
  Array(object.send(association.name)).each_with_index do |child, index|
76
- @logged = true if ::EffectiveLogging::ActiveRecordLogger.new(child, options.merge(logger: logger, depth: depth+1, prefix: "#{title} #{index} - #{child} - ")).execute!
78
+ child_options = options.merge(logger: logger, depth: depth+1, include_associated: include_associated, prefix: "#{title} #{index} - #{child} - ")
79
+ @logged = true if ::EffectiveLogging::ActiveRecordLogger.new(child, child_options).execute!
77
80
  end
78
81
  end
79
82
  end
@@ -114,6 +117,5 @@ module EffectiveLogging
114
117
  # Blacklist
115
118
  atts.except(:logged_changes, :trash, 'logged_changes', 'trash')
116
119
  end
117
-
118
120
  end
119
121
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '2.0.3'.freeze
2
+ VERSION = '2.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect