dead_code_detector 0.0.10 → 0.0.12

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
  SHA256:
3
- metadata.gz: 60644539c351c9c6fba75e96f9a0e0b1509d9d2fb5b392613f5ee396d01fc170
4
- data.tar.gz: b56f91fc57521d3405db882b51b2051972132e8af36663e7eb468a75e0633c00
3
+ metadata.gz: b1e25ae55d24dbc0c957f819cbe68bb4db71d71fba805505b3a72db1d8446426
4
+ data.tar.gz: 46ab5c442af8cfbe750e7fd596fd0f4816d417ccfb424f28f19add022f0a1f53
5
5
  SHA512:
6
- metadata.gz: b18b4fe4c42e4fd445faf30afd2a74110d819b3518f23f7d7ad3803ca6f72bd58edaf4d02abef4991d1f2a171b0a808e15a3edb4a7cd4ac3521e70e9ef8bc343
7
- data.tar.gz: 8ddce2288950a82afe6674151918e2c130eb331c37f0b6e32485343b85686a36b1381f44e098f8e2611f7b008b8e925bc2c5dce3f16b64a6100777db77cb3fe0
6
+ metadata.gz: 0ba9ee6774898c90413e24aacccc82bb40be0a6a1af54018f2c1ba0f99a6bb8df02b4c7f568745feaeef88dcad17fb5af42fb3a30bfbdcf09575d1ca92f286f1
7
+ data.tar.gz: 274a69dba37db8a83851bc4021ae9d5da98252901ae0e990466d66bf0888af1f89fc21c7ffcd80c44db1e7e5a2585b3e7e104e425a1f0093f48715b88d29028b
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dead_code_detector (0.0.10)
4
+ dead_code_detector (0.0.12)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  byebug (11.0.1)
10
10
  diff-lcs (1.3)
11
- rake (10.5.0)
11
+ rake (13.0.1)
12
12
  rspec (3.7.0)
13
13
  rspec-core (~> 3.7.0)
14
14
  rspec-expectations (~> 3.7.0)
@@ -30,7 +30,7 @@ DEPENDENCIES
30
30
  bundler (~> 1.17)
31
31
  byebug
32
32
  dead_code_detector!
33
- rake (~> 10.0)
33
+ rake (~> 13.0)
34
34
  rspec (~> 3.0)
35
35
 
36
36
  BUNDLED WITH
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.require_paths = ["lib"]
34
34
 
35
35
  spec.add_development_dependency "bundler", "~> 1.17"
36
- spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rake", "~> 13.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
38
  spec.add_development_dependency "byebug"
39
39
  end
@@ -33,7 +33,9 @@ module DeadCodeDetector
33
33
 
34
34
  def refresh_cache
35
35
  clear_cache
36
- DeadCodeDetector.config.storage.add(self.class.record_key(klass.name), default_methods)
36
+ if default_methods.any?
37
+ DeadCodeDetector.config.storage.add(self.class.record_key(klass.name), default_methods)
38
+ end
37
39
  end
38
40
 
39
41
  private
@@ -24,7 +24,7 @@ module DeadCodeDetector
24
24
 
25
25
  def wrap_method(original_method)
26
26
  original_class = klass
27
- klass.define_singleton_method(original_method.name) do |*args, &block|
27
+ klass.define_singleton_method(original_method.name) do |*args, **kwargs, &block|
28
28
  begin
29
29
  DeadCodeDetector::ClassMethodWrapper.unwrap_method(original_class, original_method)
30
30
  rescue StandardError => e
@@ -39,7 +39,7 @@ module DeadCodeDetector
39
39
  # is calling the method
40
40
  unbound_method = original_method.unbind
41
41
  method_bound_to_caller = unbound_method.bind(self)
42
- method_bound_to_caller.call(*args, &block)
42
+ method_bound_to_caller.call(*args, **kwargs, &block)
43
43
  end
44
44
  end
45
45
 
@@ -53,12 +53,17 @@ module DeadCodeDetector
53
53
  return true if DeadCodeDetector.config.ignore_paths.nil?
54
54
  source_location = klass.method(method_name).source_location&.first
55
55
  return false if source_location.nil?
56
+ return false if source_location == "(eval)"
56
57
  source_location !~ DeadCodeDetector.config.ignore_paths
57
58
  end
58
59
 
59
60
  def owned_method?(method_name)
60
61
  original_method = klass.method(method_name)
61
- klass.singleton_class <= original_method.owner && !(klass.superclass.singleton_class <= original_method.owner)
62
+ if klass.respond_to?(:superclass)
63
+ klass.singleton_class <= original_method.owner && !(klass.superclass.singleton_class <= original_method.owner)
64
+ else
65
+ klass.singleton_class <= original_method.owner
66
+ end
62
67
  end
63
68
 
64
69
  end
@@ -1,7 +1,7 @@
1
1
  module DeadCodeDetector
2
2
  class Configuration
3
3
 
4
- attr_accessor :redis, :classes_to_monitor, :error_handler, :allowed, :cache_expiry, :ignore_paths
4
+ attr_accessor :redis, :classes_to_monitor, :error_handler, :allowed, :cache_expiry, :ignore_paths, :max_seconds_to_enable
5
5
 
6
6
  STORAGE_BACKENDS = {
7
7
  memory: Storage::MemoryBackend,
@@ -12,6 +12,7 @@ module DeadCodeDetector
12
12
  @allowed = true
13
13
  @classes_to_monitor = []
14
14
  @cache_expiry = 60 * 60 * 24 * 14
15
+ @max_seconds_to_enable = 1
15
16
  end
16
17
 
17
18
  def storage=(backend_type)
@@ -3,6 +3,8 @@ module DeadCodeDetector
3
3
 
4
4
  class << self
5
5
 
6
+ attr_accessor :fully_enabled, :last_enabled_class
7
+
6
8
  def refresh_caches
7
9
  DeadCodeDetector.config.classes_to_monitor.each do |klass|
8
10
  refresh_cache_for(klass)
@@ -10,7 +12,8 @@ module DeadCodeDetector
10
12
  end
11
13
 
12
14
  def refresh_cache_for(klass)
13
- @enabled = false
15
+ self.fully_enabled = false
16
+ self.last_enabled_class = nil
14
17
  classes = [klass, *descendants_of(klass)]
15
18
  classes.each do |class_to_enable|
16
19
  cache_methods_for(class_to_enable)
@@ -34,13 +37,18 @@ module DeadCodeDetector
34
37
  end
35
38
 
36
39
  def enable_for_cached_classes!
37
- return if @enabled
40
+ return if fully_enabled
38
41
  return unless allowed?
39
- @enabled = true
40
- cached_classes.each do |class_name|
42
+ classes = cached_classes.sort.to_a
43
+ starting_index = (classes.index(last_enabled_class) || -1) + 1
44
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
45
+ classes[starting_index..-1].each do |class_name|
41
46
  klass = Object.const_get(class_name) rescue nil
42
47
  enable(klass) if klass
48
+ self.last_enabled_class = class_name
49
+ return if Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time > DeadCodeDetector.config.max_seconds_to_enable
43
50
  end
51
+ self.fully_enabled = true
44
52
  end
45
53
 
46
54
  def allowed?
@@ -57,7 +65,9 @@ module DeadCodeDetector
57
65
 
58
66
  private
59
67
  def descendants_of(parent_class)
60
- ObjectSpace.each_object(parent_class.singleton_class).select { |klass| klass < parent_class }
68
+ ObjectSpace.each_object(parent_class.singleton_class).select do |klass|
69
+ klass < parent_class && !klass.name.nil?
70
+ end
61
71
  end
62
72
 
63
73
  def cache_methods_for(klass)
@@ -24,7 +24,7 @@ module DeadCodeDetector
24
24
 
25
25
  def wrap_method(original_method)
26
26
  original_class = klass
27
- klass.send(:define_method, original_method.name) do |*args, &block|
27
+ klass.send(:define_method, original_method.name) do |*args, **kwargs, &block|
28
28
  begin
29
29
  DeadCodeDetector::InstanceMethodWrapper.unwrap_method(original_class, original_method)
30
30
  rescue StandardError => e
@@ -33,7 +33,7 @@ module DeadCodeDetector
33
33
  end
34
34
  end
35
35
  method_bound_to_caller = original_method.bind(self)
36
- method_bound_to_caller.call(*args, &block)
36
+ method_bound_to_caller.call(*args, **kwargs, &block)
37
37
  end
38
38
  end
39
39
 
@@ -47,12 +47,17 @@ module DeadCodeDetector
47
47
  return true if DeadCodeDetector.config.ignore_paths.nil?
48
48
  source_location = klass.instance_method(method_name).source_location&.first
49
49
  return false if source_location.nil?
50
+ return false if source_location == "(eval)"
50
51
  source_location !~ DeadCodeDetector.config.ignore_paths
51
52
  end
52
53
 
53
54
  def owned_method?(method_name)
54
55
  original_method = klass.instance_method(method_name)
55
- klass <= original_method.owner && !(klass.superclass <= original_method.owner)
56
+ if klass.respond_to?(:superclass)
57
+ klass <= original_method.owner && !(klass.superclass <= original_method.owner)
58
+ else
59
+ klass <= original_method.owner
60
+ end
56
61
  end
57
62
 
58
63
  end
@@ -1,3 +1,3 @@
1
1
  module DeadCodeDetector
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.12"
3
3
  end
data/overlord.yml ADDED
@@ -0,0 +1 @@
1
+ tier: 4
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dead_code_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle d'Oliveira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-15 00:00:00.000000000 Z
11
+ date: 2023-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,13 +96,14 @@ files:
96
96
  - lib/dead_code_detector/storage/memory_backend.rb
97
97
  - lib/dead_code_detector/storage/redis_backend.rb
98
98
  - lib/dead_code_detector/version.rb
99
+ - overlord.yml
99
100
  homepage: https://github.com/clio/dead_code_detector
100
101
  licenses:
101
102
  - MIT
102
103
  metadata:
103
104
  homepage_uri: https://github.com/clio/dead_code_detector
104
105
  source_code_uri: https://github.com/clio/dead_code_detector
105
- post_install_message:
106
+ post_install_message:
106
107
  rdoc_options: []
107
108
  require_paths:
108
109
  - lib
@@ -117,8 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  requirements: []
120
- rubygems_version: 3.0.3
121
- signing_key:
121
+ rubygems_version: 3.2.33
122
+ signing_key:
122
123
  specification_version: 4
123
124
  summary: Help find unused code in production.
124
125
  test_files: []