Class: GetCloneData::ClonedRepo
- Inherits:
-
Object
- Object
- GetCloneData::ClonedRepo
- Defined in:
- lib/getclonedata/getclonedata_clonerepo.rb
Constant Summary collapse
- CLONED_REPO_PATH =
File.( File.join( File.dirname(__FILE__), '..', '..', 'cloned_repo_tmp' ) )
- @@itt =
0
Instance Attribute Summary collapse
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
Class Method Summary collapse
Instance Method Summary collapse
- #get_flay_score ⇒ Object
- #get_flog_scores ⇒ Object
- #get_loc ⇒ Object
- #get_rubocop_errors ⇒ Object
-
#initialize(repo_path:) ⇒ ClonedRepo
constructor
A new instance of ClonedRepo.
- #ruby_files ⇒ Object
- #wipe ⇒ Object
Constructor Details
#initialize(repo_path:) ⇒ ClonedRepo
Returns a new instance of ClonedRepo.
14 15 16 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 14 def initialize(repo_path:) @repo_path = repo_path end |
Instance Attribute Details
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
12 13 14 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 12 def repo_path @repo_path end |
Class Method Details
.clone(git_url:) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 18 def self.clone(git_url:) repo_path = self.get_repo_path(git_url: git_url) `git clone --depth=1 #{git_url} #{repo_path}` return nil unless Dir.exists? repo_path new(repo_path: repo_path) end |
.get_repo_path(git_url:) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 33 def self.get_repo_path(git_url:) owner, repo = git_url.gsub('.git','').split('/')[3,4] File.( File.join( CLONED_REPO_PATH, owner, repo, itt.to_s ) ) end |
.itt ⇒ Object
42 43 44 45 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 42 def self.itt @@itt = @@itt + 1 @@itt end |
.wipe ⇒ Object
25 26 27 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 25 def self.wipe `rm -R -f #{CLONED_REPO_PATH}/*` end |
Instance Method Details
#get_flay_score ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 70 def get_flay_score if Dir.exist? @repo_path flay = Flay.new flay.process(*ruby_files) flay.analyze flay = flay.summary.values.first end flay if flay end |
#get_flog_scores ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 55 def get_flog_scores if Dir.exist? @repo_path flog = Flog.new flog.flog(*ruby_files) #flog.calculate_total_score flog_response = { total_score: flog.total_score, max_score: flog.max_score, average: flog.average } end # reponse is an array of all the flog scores from total , ave, each method... flog_response if flog_response end |
#get_loc ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 88 def get_loc if Dir.exist? @repo_path loc_response = `cloc #{@repo_path}` if loc_response.empty? loc_response = nil else loc_response = loc_response.split('SUM').last.split("\n").first .split(' ')[2..5].map(&:to_f) end end loc_response end |
#get_rubocop_errors ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 80 def get_rubocop_errors if Dir.exist? @repo_path rubocop_response = `cd #{@repo_path} ; rubocop --format json` summary = JSON.parse(rubocop_response, :symbolize_names => true)[:summary] summary end end |
#ruby_files ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 47 def ruby_files return @ruby_files if @ruby_files = PathExpander.new [@repo_path], "**/*.{rb,rake}" @ruby_files = .process @ruby_files end |
#wipe ⇒ Object
29 30 31 |
# File 'lib/getclonedata/getclonedata_clonerepo.rb', line 29 def wipe `rm -R -f #{@repo_path}` end |