fukuzatsu 0.9.6 → 0.9.7

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: 622d8c7306555088bb10339f778eae368dab9968
4
- data.tar.gz: 60dee104888382877a90a9e542cab6420b723280
3
+ metadata.gz: efab3a434a8c65a1adb32fd0d7094305b2b9d0af
4
+ data.tar.gz: 5c00a9a29a444a828ef9004ed6dd49973daf487d
5
5
  SHA512:
6
- metadata.gz: 87e0a9c75f497346fbd7accdbb3a317b46e558f4b26bd41e49f11dd11e3d411a2eb0a8b803918b1228b74af6d03e7cecc625e7445028a42c65575e558d14e26a
7
- data.tar.gz: 460ed046491b966a49184391af65b060956935083b730ead9f9d880ab8a1cb43148cd49ed594687e2500a0aa1c240ce61c71cf9806a033b47bf3d5ab11712c31
6
+ metadata.gz: ae7fe25e982c111c13744a8d07ed9699e987a20d8ba15decd8cb2bc367e8f04e790b828968a0a69d94a0b98eadf88468288e2dbe19cb103d46c4f41a95ca8252
7
+ data.tar.gz: e10e18df2971b516b966508d68a747564e09a5a81fe344c058fbc0d6eb8cd0f7376b7b9c921895d41091d1e034a2ce17cd2f9b849535ecc9249308eda12e2d56
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
2
7
 
@@ -24,12 +24,25 @@ class Analyzer
24
24
 
25
25
  def extract_class_name
26
26
  return self.class_name if self.class_name
27
- name = parsed.children.select{|node| node.type == :class}.first.loc.name
27
+ child = find_class(parsed)
28
+ return "?" unless child
29
+ name = child.loc.name
28
30
  self.class_name = self.content[name.begin_pos..(name.end_pos - 1)]
29
31
  end
30
32
 
31
33
  private
32
34
 
35
+ def find_class(parsed)
36
+ return parsed if parsed.respond_to?(:type) && (parsed.type == :class || (parsed.type == :module && parsed.children.empty?))
37
+ child_nodes = parsed.respond_to?(:children) ? parsed.children : parsed
38
+ child_nodes.each do |child_node|
39
+ next unless child_node.respond_to?(:type)
40
+ return child_node if child_node.type == :class
41
+ return find_class(child_node.children) if child_node.type == :module
42
+ end
43
+ false
44
+ end
45
+
33
46
  def extend_graph
34
47
  self.edges += 2
35
48
  self.nodes += 2
data/lib/fukuzatsu/cli.rb CHANGED
@@ -5,17 +5,44 @@ module Fukuzatsu
5
5
 
6
6
  class CLI < Thor
7
7
 
8
- desc "parse PATH_TO_FILE -f FORMAT", "Formats are text (default, to STDOUT), html, and csv. Ex: parse foo.rb -f html"
8
+ desc_text = "Formats are text (default, to STDOUT), html, and csv. "
9
+ desc_text << "Example: fuku check foo/ -f html"
10
+
11
+ desc "check PATH_TO_FILE [-f FORMAT] [-t MAX_COMPLEXITY_ALLOWED]", desc_text
9
12
  method_option :format, :type => :string, :default => 'text', :aliases => "-f"
10
- def parse(file)
11
- file = ParsedFile.new(path_to_file: file)
12
- case options['format']
13
- when 'html'
14
- Formatters::Html.new(file).export
15
- when 'csv'
16
- Formatters::Csv.new(file).export
13
+ method_option :threshold, :type => :numeric, :default => 0, :aliases => "-t"
14
+
15
+ def check(path)
16
+
17
+ file_complexities = file_list(path).map do |file|
18
+ file = ParsedFile.new(path_to_file: file)
19
+ case options['format']
20
+ when 'html'
21
+ Formatters::Html.new(file).export
22
+ when 'csv'
23
+ Formatters::Csv.new(file).export
24
+ else
25
+ Formatters::Text.new(file).export
26
+ end
27
+ file.complexity
28
+ end
29
+
30
+ highest_complexity = file_complexities.sort.last
31
+
32
+ if options['threshold'] != 0 && highest_complexity > options['threshold']
33
+ puts "Maximum complexity is #{highest_complexity}, which is greater than the threshold of #{options['threshold']}."
34
+ exit 1
35
+ end
36
+
37
+ end
38
+
39
+ private
40
+
41
+ def file_list(start_file)
42
+ if File.directory?(start_file)
43
+ return Dir.glob(File.join(start_file, "**", "*")).select{|n| n =~ /\.rb$/}
17
44
  else
18
- Formatters::Text.new(file).export
45
+ return [start_file]
19
46
  end
20
47
  end
21
48
 
@@ -0,0 +1 @@
1
+ util.rb
@@ -1,3 +1,3 @@
1
1
  module Fukuzatsu
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
@@ -0,0 +1 @@
1
+ program_4.rb
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fukuzatsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bantik
@@ -149,11 +149,13 @@ files:
149
149
  - lib/fukuzatsu/formatters/text.rb
150
150
  - lib/fukuzatsu/parsed_file.rb
151
151
  - lib/fukuzatsu/parsed_method.rb
152
+ - lib/fukuzatsu/util.rb
152
153
  - lib/fukuzatsu/version.rb
153
154
  - spec/analyzer_spec.rb
154
155
  - spec/fixtures/program_1.rb
155
156
  - spec/fixtures/program_2.rb
156
157
  - spec/fixtures/program_3.rb
158
+ - spec/fixtures/program_4.rb
157
159
  - spec/spec_helper.rb
158
160
  homepage: https://gitlab.com/coraline/fukuzatsu/tree/master
159
161
  licenses:
@@ -184,4 +186,5 @@ test_files:
184
186
  - spec/fixtures/program_1.rb
185
187
  - spec/fixtures/program_2.rb
186
188
  - spec/fixtures/program_3.rb
189
+ - spec/fixtures/program_4.rb
187
190
  - spec/spec_helper.rb