is_this_used 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fef7d87d65b79a4f07d5fca612b292cc9875240461b778ef7826df8145740c6d
4
- data.tar.gz: c2c8c33b2e8e6eb2a81510b744a88a6183d9e95b366c8df10a1d542de3a9d762
3
+ metadata.gz: f1ec2b933a1f12af4ad52b177d002da0836fdec563fa7745d601ab98f2fbecf3
4
+ data.tar.gz: 6bb9f7d494a1c0419ef76b8a97f19a47d6b65387063ba712a58fe6e42940ef1d
5
5
  SHA512:
6
- metadata.gz: d79392e8b8ea752d282a4dd216ec6a1c73a215eb0e88c1968bc88a22495b568b0204f8e1a4e96faaff99407325b172f5d792189ebd8e2ea48b8df26907286d62
7
- data.tar.gz: 03fe4938315337b39b3238f35be6d2dafd42fb2d5c094a89f769432db88420be3204831a303b84129d29480556839b876d2ca2d87ffde285d9c94524f7121cdd
6
+ metadata.gz: cc6580e73c52a2550f49ef9c89f9fa12903ed5bf12c5a69d1bbf2ce71d50ce48f90463243be3397cdedc0f17aa8a4143117c504cafa21e472f5ffc1efc0bc01f
7
+ data.tar.gz: 46ec1e8ad793378629ac0276351631a277e383e80933b6a869d416d5f964fa37893f1a1fb843067e902031b996278b7879e04161e55e1b18ad0df0da5c07f1f0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- is_this_used (0.1.1)
4
+ is_this_used (0.1.2)
5
5
  activerecord (>= 5.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- is_this_used (0.1.1)
4
+ is_this_used (0.1.2)
5
5
  activerecord (>= 5.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- is_this_used (0.1.1)
4
+ is_this_used (0.1.2)
5
5
  activerecord (>= 5.2)
6
6
 
7
7
  GEM
@@ -39,7 +39,9 @@ module IsThisUsed
39
39
 
40
40
  def self.filtered_stack
41
41
  caller_locations.reject do |location|
42
- location.path.match?(%r{\/lib\/is_this_used\/cruft_tracker.rb$})
42
+ location.path.match?(
43
+ %r{\/lib\/is_this_used\/(cruft_tracker.rb|util\/log_suppressor.rb)$}
44
+ )
43
45
  end.map do |location|
44
46
  {
45
47
  path: location.path,
@@ -53,23 +55,26 @@ module IsThisUsed
53
55
 
54
56
  class_methods do
55
57
  def is_this_used?(method_name, method_type: nil)
56
- method_type ||= determine_method_type(method_name)
57
- target_method = target_method(method_name, method_type)
58
-
59
- potential_cruft =
60
- PotentialCruft.find_or_create_by(
61
- owner_name: self.name,
62
- method_name: method_name,
63
- method_type: method_type
64
- )
65
-
66
- target_method.owner.define_method target_method.name do |*args|
67
- CruftTracker::Recorder.record_invocation(potential_cruft)
68
-
69
- if method_type == INSTANCE_METHOD
70
- target_method.bind(self).call(*args)
71
- else
72
- target_method.call(*args)
58
+ IsThisUsed::Util::LogSuppressor.suppress_logging do
59
+ method_type ||= determine_method_type(method_name)
60
+ target_method = target_method(method_name, method_type)
61
+
62
+ potential_cruft =
63
+ PotentialCruft.find_or_create_by(
64
+ owner_name: self.name,
65
+ method_name: method_name,
66
+ method_type: method_type
67
+ )
68
+
69
+ target_method.owner.define_method target_method.name do |*args|
70
+ IsThisUsed::Util::LogSuppressor.suppress_logging do
71
+ CruftTracker::Recorder.record_invocation(potential_cruft)
72
+ end
73
+ if method_type == INSTANCE_METHOD
74
+ target_method.bind(self).call(*args)
75
+ else
76
+ target_method.call(*args)
77
+ end
73
78
  end
74
79
  end
75
80
  rescue ActiveRecord::StatementInvalid => e
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsThisUsed
4
+ module Util
5
+ class LogSuppressor
6
+ def self.suppress_logging
7
+ initial_log_level = ActiveRecord::Base.logger.level
8
+ ActiveRecord::Base.logger.level = :error
9
+ yield
10
+ ActiveRecord::Base.logger.level = initial_log_level
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IsThisUsed
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/is_this_used.rb CHANGED
@@ -2,6 +2,7 @@ require 'is_this_used/version'
2
2
  require 'is_this_used/cruft_tracker'
3
3
  require 'is_this_used/models/potential_cruft'
4
4
  require 'is_this_used/models/potential_cruft_stack'
5
+ require 'is_this_used/util/log_suppressor'
5
6
 
6
7
  module IsThisUsed
7
8
  class Error < StandardError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is_this_used
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Hughes
@@ -238,6 +238,7 @@ files:
238
238
  - lib/is_this_used/cruft_tracker.rb
239
239
  - lib/is_this_used/models/potential_cruft.rb
240
240
  - lib/is_this_used/models/potential_cruft_stack.rb
241
+ - lib/is_this_used/util/log_suppressor.rb
241
242
  - lib/is_this_used/version.rb
242
243
  - log/test.log
243
244
  homepage: https://github.com/dhughes/is_this_used