debride 1.1.0 → 1.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: d36c868e7a15b6746112225734bc0d747df00d6e
4
- data.tar.gz: 84d0559594fe52021133115507afcea6974b3967
3
+ metadata.gz: bb39a05e306cbbcd061e35997220368ac0cbd964
4
+ data.tar.gz: 0704f659f6af475a29e97b424eeecb9ef66b1b8a
5
5
  SHA512:
6
- metadata.gz: 427ce5bf52dd04e4060da5c417fbe90cf918e2e39104b72da41ad3335aac76d359501aa33f4dbdb17b664f55391d2372aeafbb814beaf98d2b018593cae9b3e3
7
- data.tar.gz: 19e156808348e4a005febc69774523634cbc2fb3798717a8cfe7bc6516544c1786b858867ef8bc83b7fb9dae30c189e86648c9585cfb73a9c358473219488787
6
+ metadata.gz: a33032ea66b7b298f0a922978bb3f70b1fdd983bf1147e442fddaf8188be6695b81be4430b32135a4130d1893281d437683e58d8a90b02a533e3909b768edb27
7
+ data.tar.gz: 0bcaa9a023b64733d5def8e8cec519328b21bb7a68fa8bf1da74aa7284e031ccc9fc2a4ec7692f037af5b0017400665772d88d9395bb3b5c08c28c16d953804e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,13 @@
1
+ === 1.2.0 / 2015-03-26
2
+
3
+ * 1 major enhancement:
4
+
5
+ * Added plugin system to allow processing of other file types.
6
+
7
+ * 1 minor enhancement:
8
+
9
+ * Refactored code to allow for plugin system to do multi-phase processing.
10
+
1
11
  === 1.1.0 / 2015-03-18
2
12
 
3
13
  * 1 minor enhancement:
data/Rakefile CHANGED
@@ -15,4 +15,10 @@ Hoe.spec "debride" do
15
15
  dependency "ruby_parser", "~> 3.6"
16
16
  end
17
17
 
18
+ task :rails do
19
+ ENV["GEM_HOME"] = "tmp/isolate/ruby-2.0.0"
20
+ ENV["GEM_PATH"] = "../../debride-erb/dev/tmp/isolate/ruby-2.0.0"
21
+ ruby "-Ilib:../../debride-erb/dev/lib bin/debride ~/Work/git/seattlerb.org/{app,lib} --whitelist ~/Work/git/seattlerb.org/whitelist.txt"
22
+ end
23
+
18
24
  # vim: syntax=ruby
@@ -9,7 +9,48 @@ require "set"
9
9
  # A static code analyzer that points out possible dead methods.
10
10
 
11
11
  class Debride < MethodBasedSexpProcessor
12
- VERSION = "1.1.0" # :nodoc:
12
+ VERSION = "1.2.0" # :nodoc:
13
+ PROJECT = "debride"
14
+
15
+ def self.expand_dirs_to_files *dirs # TODO: push back up to sexp_processor
16
+ extensions = self.file_extensions
17
+
18
+ dirs.flatten.map { |p|
19
+ if File.directory? p then
20
+ Dir[File.join(p, "**", "*.{#{extensions.join(",")}}")]
21
+ else
22
+ p
23
+ end
24
+ }.flatten.map { |s| s.sub(/^\.\//, "") } # strip "./" from paths
25
+ end
26
+
27
+ def self.load_plugins proj = PROJECT
28
+ unless defined? @@plugins then
29
+ @@plugins = []
30
+
31
+ task_re = /#{PROJECT}_task/o
32
+ plugins = Gem.find_files("#{PROJECT}_*.rb").reject { |p| p =~ task_re }
33
+
34
+ plugins.each do |plugin|
35
+ plugin_name = File.basename(plugin, ".rb").sub(/^#{PROJECT}_/o, "")
36
+ next if @@plugins.include? plugin_name
37
+ begin
38
+ load plugin
39
+ @@plugins << plugin_name
40
+ rescue LoadError => e
41
+ warn "error loading #{plugin.inspect}: #{e.message}. skipping..."
42
+ end
43
+ end
44
+ end
45
+
46
+ @@plugins
47
+ rescue
48
+ # ignore
49
+ end
50
+
51
+ def self.file_extensions
52
+ %w[rb rake] + load_plugins
53
+ end
13
54
 
14
55
  ##
15
56
  # Top level runner for bin/debride.
@@ -17,15 +58,38 @@ class Debride < MethodBasedSexpProcessor
17
58
  def self.run args
18
59
  opt = parse_options args
19
60
 
20
- callers = Debride.new opt
61
+ debride = Debride.new opt
62
+ debride.run expand_dirs_to_files(args)
63
+ debride
64
+ end
65
+
66
+ def run(*files)
67
+ files.flatten.each do |file|
68
+ warn "Processing #{file}" if option[:verbose]
69
+
70
+ ext = File.extname(file).sub(/^\./, "")
71
+ ext = "rb" if ext.nil? || ext.empty?
72
+ msg = "process_#{ext}"
21
73
 
22
- expand_dirs_to_files(args).each do |path|
23
- warn "processing: #{path}" if opt[:verbose]
24
- parser = RubyParser.new
25
- callers.process parser.process File.read(path), path
74
+ unless respond_to? msg then
75
+ warn " Unknown file type: #{ext}, defaulting to ruby" if option[:verbose]
76
+ msg = "process_rb"
77
+ end
78
+
79
+ begin
80
+ process send(msg, file)
81
+ rescue RuntimeError, SyntaxError => e
82
+ warn " skipping #{file}: #{e.message}"
83
+ end
26
84
  end
85
+ end
27
86
 
28
- callers
87
+ def process_rb file
88
+ begin
89
+ RubyParser.new.process(File.binread(file), file, option[:timeout])
90
+ rescue Timeout::Error
91
+ warn "TIMEOUT parsing #{file}. Skipping."
92
+ end
29
93
  end
30
94
 
31
95
  ##
@@ -114,9 +178,11 @@ class Debride < MethodBasedSexpProcessor
114
178
 
115
179
  def process_call sexp # :nodoc:
116
180
  method_name = sexp[2]
117
- method_name = :initialize if method_name == :new
118
181
 
119
- if method_name == :alias_method_chain
182
+ case method_name
183
+ when :new then
184
+ method_name = :initialize
185
+ when :alias_method_chain
120
186
  known[sexp[3]] << klass_name
121
187
  end
122
188
 
@@ -10,7 +10,7 @@ class TestDebride < Minitest::Test
10
10
  end
11
11
 
12
12
  exp = [["Debride",
13
- [:process_call, :process_defn, :process_defs, :report, :run]]]
13
+ [:process_call, :process_defn, :process_defs, :process_rb, :report]]]
14
14
 
15
15
  assert_equal exp, debride.missing
16
16
  end
@@ -41,7 +41,7 @@ class TestDebride < Minitest::Test
41
41
  debride.option[:whitelist] = %w[process_defn]
42
42
 
43
43
  exp = [["Debride",
44
- [:process_call, :process_defs, :report, :run]]]
44
+ [:process_call, :process_defs, :process_rb, :report]]]
45
45
 
46
46
  assert_equal exp, debride.missing
47
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debride
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  xJcC6UN6NHMOVMyAXsr2HR0gRRx4ofN1LoP2KhXzSr8UMvQYlwPmE0N5GQv1b5AO
30
30
  VpzF30vNaJK6ZT7xlIsIlwmH
31
31
  -----END CERTIFICATE-----
32
- date: 2015-03-18 00:00:00.000000000 Z
32
+ date: 2015-03-27 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
metadata.gz.sig CHANGED
Binary file