Class: Codescout::RepoAnalyzer
- Inherits:
-
Object
- Object
- Codescout::RepoAnalyzer
- Defined in:
- lib/codescout/repo_analyzer.rb
Constant Summary collapse
- ALLOWED_FILES =
%w(.rb .rake .gemspec)
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
- #analyze ⇒ Object
- #cleanup ⇒ Object
-
#initialize(path) ⇒ RepoAnalyzer
constructor
A new instance of RepoAnalyzer.
- #result ⇒ Object
- #run_brakeman ⇒ Object
- #run_churn ⇒ Object
- #run_commitstats ⇒ Object
- #run_filestats ⇒ Object
- #run_flay ⇒ Object
- #run_flog ⇒ Object
- #run_rubocop ⇒ Object
- #scan_files ⇒ Object
- #valid_file?(file) ⇒ Boolean
- #within_base(&blk) ⇒ Object
Constructor Details
#initialize(path) ⇒ RepoAnalyzer
7 8 9 10 11 12 13 |
# File 'lib/codescout/repo_analyzer.rb', line 7 def initialize(path) @base_path = File.(path) @files = [] @codescout = { version: Codescout::VERSION } end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/codescout/repo_analyzer.rb', line 5 def base_path @base_path end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
5 6 7 |
# File 'lib/codescout/repo_analyzer.rb', line 5 def files @files end |
Instance Method Details
#analyze ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/codescout/repo_analyzer.rb', line 15 def analyze within_base do scan_files run_filestats run_flog run_flay run_churn run_brakeman run_rubocop run_commitstats cleanup end end |
#cleanup ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/codescout/repo_analyzer.rb', line 93 def cleanup files = %w(./rubocop.yml ./rubocop.json ./tmp/churn ./brakeman.json) files.each do |path| FileUtils.rm_rf(path) end end |
#result ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/codescout/repo_analyzer.rb', line 29 def result { codescout: @codescout, file_stats: @file_stats, flog: @flog, flay: @flay, churn: @churn, brakeman: @brakeman, rubocop: @rubocop, commit: @commit } end |
#run_brakeman ⇒ Object
78 79 80 81 |
# File 'lib/codescout/repo_analyzer.rb', line 78 def run_brakeman STDERR.puts "Running brakeman" @brakeman = Codescout::BrakemanStats.new(self).results end |
#run_churn ⇒ Object
73 74 75 76 |
# File 'lib/codescout/repo_analyzer.rb', line 73 def run_churn STDERR.puts "Running churn" @churn = Codescout::ChurnStats.new(self).files end |
#run_commitstats ⇒ Object
88 89 90 91 |
# File 'lib/codescout/repo_analyzer.rb', line 88 def run_commitstats STDERR.puts "Runnig commit stats" @commit = Codescout::CommitStats.new(self).to_hash end |
#run_filestats ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/codescout/repo_analyzer.rb', line 60 def run_filestats STDERR.puts "Running filestats" @file_stats = {} @files.each do |f| @file_stats[f] = Codescout::FileStats.new(@base_path, f).to_hash end if File.exists?("Gemfile") @file_stats["Gemfile"] = Codescout::FileStats.new(@base_path, "Gemfile").to_hash end end |
#run_flay ⇒ Object
50 51 52 53 |
# File 'lib/codescout/repo_analyzer.rb', line 50 def run_flay STDERR.puts "Running flay" @flay = Codescout::FlayStats.new(self).matches end |
#run_flog ⇒ Object
55 56 57 58 |
# File 'lib/codescout/repo_analyzer.rb', line 55 def run_flog STDERR.puts "Running flog" @flog = Codescout::FlogStats.new(self).scores end |
#run_rubocop ⇒ Object
83 84 85 86 |
# File 'lib/codescout/repo_analyzer.rb', line 83 def run_rubocop STDERR.puts "Running rubocop" @rubocop = Codescout::RubocopStats.new(self).results end |
#scan_files ⇒ Object
46 47 48 |
# File 'lib/codescout/repo_analyzer.rb', line 46 def scan_files Dir["**/*"].each { |file| @files << file if valid_file?(file) } end |
#valid_file?(file) ⇒ Boolean
101 102 103 104 105 |
# File 'lib/codescout/repo_analyzer.rb', line 101 def valid_file?(file) return false unless ALLOWED_FILES.include?(File.extname(file)) return false if file =~ /^db|spec|features|test|examples|samples\// true end |
#within_base(&blk) ⇒ Object
42 43 44 |
# File 'lib/codescout/repo_analyzer.rb', line 42 def within_base(&blk) Dir.chdir(@base_path) { blk.call } end |