dead_code_detector 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dead_code_detector/base_method_wrapper.rb +3 -1
- data/lib/dead_code_detector/class_method_wrapper.rb +6 -1
- data/lib/dead_code_detector/configuration.rb +2 -1
- data/lib/dead_code_detector/initializer.rb +15 -5
- data/lib/dead_code_detector/instance_method_wrapper.rb +6 -1
- data/lib/dead_code_detector/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b4f7f42c5f2d8764222099b8c490898dfc9c75d8b8223b09c13c065a9d1acc8
|
4
|
+
data.tar.gz: 0407b8f7e3a8e5acc55eb1c8121637ed97017208d868b82d5127f901318aa903
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dbe80ea179ff3215fcffd403a9750ef4d5cf3617249beb5b516222dcfa56b3ef65729d67c27d8bf4ae9d89ee70a934e7ea9d1e961406411e6c732fc63035048
|
7
|
+
data.tar.gz: cb047ce6a066dd8884dc13f6f2f0259120ce9071c91662aa58bea84bc77609eb252702af96bfbe2f3ec91ab78e3aa63cf02cf55908f105e678b9c28c5ce46091
|
@@ -33,7 +33,9 @@ module DeadCodeDetector
|
|
33
33
|
|
34
34
|
def refresh_cache
|
35
35
|
clear_cache
|
36
|
-
|
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
|
@@ -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.
|
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
|
-
|
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
|
40
|
+
return if fully_enabled
|
38
41
|
return unless allowed?
|
39
|
-
|
40
|
-
|
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
|
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)
|
@@ -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
|
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
|
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.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle d'Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|