Class: Skunk::Command::Compare

Inherits:
RubyCritic::Command::Compare
  • Object
show all
Includes:
Shareable
Defined in:
lib/skunk/commands/compare.rb

Overview

Knows how to compare two branches and their skunk score average

Instance Method Summary collapse

Methods included from Shareable

#share, #sharing?

Constructor Details

#initialize(options) ⇒ Compare

Returns a new instance of Compare.



16
17
18
19
20
# File 'lib/skunk/commands/compare.rb', line 16

def initialize(options)
  super
  @options = options
  @status_reporter = Skunk::Command::StatusReporter.new(options)
end

Instance Method Details

#analyse_branch(branch) ⇒ Object

switch branch and analyse files but don’t generate a report



28
29
30
31
32
33
# File 'lib/skunk/commands/compare.rb', line 28

def analyse_branch(branch)
  ::RubyCritic::SourceControlSystem::Git.switch_branch(::RubyCritic::Config.send(branch))
  critic = critique(branch)
  ::RubyCritic::Config.send(:"#{branch}_score=", critic.skunk_score_average)
  ::RubyCritic::Config.root = branch_directory(branch)
end

#analyse_modified_filesObject

generate report only for modified files but don’t report it



36
37
38
39
40
41
42
43
# File 'lib/skunk/commands/compare.rb', line 36

def analyse_modified_files
  modified_files = ::RubyCritic::Config
                   .feature_branch_collection
                   .where(::RubyCritic::SourceControlSystem::Git.modified_files)
  ::RubyCritic::AnalysedModulesCollection.new(modified_files.map(&:path),
                                              modified_files)
  ::RubyCritic::Config.root = "#{::RubyCritic::Config.root}/compare"
end

#build_detailsObject

create a txt file with the branch score details



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/skunk/commands/compare.rb', line 46

def build_details
  details = CompareScore.new(
    ::RubyCritic::Config.base_branch,
    ::RubyCritic::Config.feature_branch,
    ::RubyCritic::Config.base_branch_score.to_f.round(2),
    ::RubyCritic::Config.feature_branch_score.to_f.round(2)
  ).message

  Skunk::Command::Output.create_directory(::RubyCritic::Config.compare_root_directory)
  File.open(build_details_path, "w") { |file| file.write(details) }
  puts details
end

#build_details_pathObject



59
60
61
# File 'lib/skunk/commands/compare.rb', line 59

def build_details_path
  "#{::RubyCritic::Config.compare_root_directory}/build_details.txt"
end

#executeObject



22
23
24
25
# File 'lib/skunk/commands/compare.rb', line 22

def execute
  compare_branches
  status_reporter
end