code_quality 0.1.8 → 0.1.9

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: ce1b29f26412c92229b44e6c88942516150530704c7497046109b4ae9c73502d
4
- data.tar.gz: 65b101687e65a2510fbc2842f5313059aa0e21f2a971179928e27e6a947305ee
3
+ metadata.gz: 4d634f37e3805714ba3225cbde5d3db73b7fcb469589c633e56ee11eabb0b7b5
4
+ data.tar.gz: 4986eb8f07b233f6bfa5b69e73218afa675c8340c4043f941d0866c7c7b877fa
5
5
  SHA512:
6
- metadata.gz: 2ef7f4e2e65635d002a2d306af20a1d075c876642bef72c66a906aafad988766ddcd5901a9d41d8b9f0d00e86aa58e8bfe686acf37a1a98e14e9655f32f01539
7
- data.tar.gz: 0da44037de11fd8dafd39badf65dc6f202dc5d3c9aa52a8684ed89c05b091238013a618700e8976e15479782636176738eb09799978f4c3936d8f38d76302adc
6
+ metadata.gz: 2173a13b383cbf4f80b1c9dbf8f03d7ea6e13001ce9444e8a26eb6347d8d22a3ef920c3bef23f5f5929fcff03947123b5c37bb016d69bf094758f27acf16b488
7
+ data.tar.gz: 95733cc0481be5adec4bdb80d19b03ea3e5fda563b5272fd064c9b2d5ce9f7f7e6b01d69915c852cbee1cd45ad305ed99a5a5b6071f29f44d783719fd695bcde
data/Rakefile CHANGED
@@ -4,3 +4,4 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
+ Rake::Task.send :load, 'tasks/code_quality.rake'
@@ -1,3 +1,3 @@
1
1
  module CodeQuality
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -12,17 +12,8 @@ namespace :code_quality do
12
12
 
13
13
  # desc "generate a report index page"
14
14
  task :generate_index => :helpers do
15
- require "erb"
16
- prepare_dir "tmp/code_quality"
17
- gem_app_dir = File.expand_path("../../../app", __FILE__)
18
- erb_file = "#{gem_app_dir}/views/code_quality/index.html.erb"
19
15
  index_path = "tmp/code_quality/index.html"
20
-
21
- # render view
22
- erb = ERB.new(File.read(erb_file))
23
- output = erb.result(binding)
24
-
25
- File.open(index_path, 'w') {|f| f.write output }
16
+ generate_index index_path
26
17
  # puts "Generate report index to #{index_path}"
27
18
  show_in_browser File.realpath(index_path)
28
19
  end
@@ -84,10 +75,44 @@ namespace :code_quality do
84
75
  end
85
76
 
86
77
  desc "code quality audit"
78
+ # e.g.: rake code_quality:quality_audit fail_fast=true
79
+ # options:
80
+ # fail_fast: to stop immediately if any audit task fails, by default fail_fast=false
81
+ # generate_index: generate a report index page to tmp/code_quality/quality_audit/index.html, by default generate_index=false
87
82
  task :quality_audit => [:"quality_audit:default"] do; end
88
83
  namespace :quality_audit do
89
84
  # default tasks
90
- task :default => [:rubycritic, :rubocop, :metric_fu, :resources] do; end
85
+ task :default => [:run_all, :resources] do; end
86
+
87
+ desc "run all audit tasks"
88
+ task :run_all => :helpers do
89
+ options = options_from_env(:fail_fast, :generate_index)
90
+ fail_fast = options.fetch(:fail_fast, "false")
91
+ generate_index = options.fetch(:generate_index, "false")
92
+ audit_tasks = [:rubycritic, :rubocop, :metric_fu]
93
+ exc = nil
94
+ audit_tasks.each do |task_name|
95
+ full_task_name = :"code_quality:quality_audit:#{task_name}"
96
+ begin
97
+ task = Rake::Task[full_task_name]
98
+ task.invoke
99
+ rescue SystemExit => exc
100
+ raise exc if fail_fast == "true"
101
+ end
102
+ end
103
+
104
+ # generate a report index page to tmp/code_quality/quality_audit/index.html
105
+ if options[:generate_index] == "true"
106
+ index_path = "tmp/code_quality/quality_audit/index.html"
107
+ @audit_tasks.each do |task_name, report|
108
+ report[:report_path].sub!("quality_audit/", "")
109
+ end
110
+ generate_index index_path
111
+ puts "Generate report index to #{index_path}"
112
+ end
113
+
114
+ audit_faild "" if exc
115
+ end
91
116
 
92
117
  # desc "prepare dir"
93
118
  task :prepare => :helpers do
@@ -332,6 +357,20 @@ namespace :code_quality do
332
357
  def open_in_browser?
333
358
  ENV["CI"].nil?
334
359
  end
360
+
361
+ def generate_index(index_path)
362
+ require "erb"
363
+ prepare_dir "tmp/code_quality"
364
+ gem_app_dir = File.expand_path("../../../app", __FILE__)
365
+ erb_file = "#{gem_app_dir}/views/code_quality/index.html.erb"
366
+
367
+ # render view
368
+ @audit_tasks ||= []
369
+ erb = ERB.new(File.read(erb_file))
370
+ output = erb.result(binding)
371
+
372
+ File.open(index_path, 'w') {|f| f.write output }
373
+ end
335
374
  end
336
375
 
337
376
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_quality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - RainChen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-20 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit