Class: RubyAppraiser::Appraisal

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-appraiser/appraisal.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Appraisal

Returns a new instance of Appraisal.



5
6
7
# File 'lib/ruby-appraiser/appraisal.rb', line 5

def initialize(options = {})
  @options = options.dup.freeze
end

Instance Method Details

#adaptersObject



35
36
37
# File 'lib/ruby-appraiser/appraisal.rb', line 35

def adapters
  @adapters ||= Set.new
end

#add_adapter(name) ⇒ Object



45
46
47
48
49
# File 'lib/ruby-appraiser/appraisal.rb', line 45

def add_adapter(name)
  Adapter::get(name).tap do |adapter|
    adapter and self.adapters << adapter
  end
end

#add_defect(defect, *args) ⇒ Object



57
58
59
60
61
62
# File 'lib/ruby-appraiser/appraisal.rb', line 57

def add_defect(defect, *args)
  unless defect.kind_of? Defect
    defect = Defect.new(defect, *args)
  end
  defects << defect if match?(defect.location)
end

#appraisersObject



39
40
41
42
43
# File 'lib/ruby-appraiser/appraisal.rb', line 39

def appraisers
  adapters.map do |adapter|
    adapter.new(self, options)
  end
end

#defectsObject



31
32
33
# File 'lib/ruby-appraiser/appraisal.rb', line 31

def defects
  @defects ||= Set.new
end

#modeObject



9
10
11
# File 'lib/ruby-appraiser/appraisal.rb', line 9

def mode
  @options.fetch(:mode) { 'all' }
end

#optionsObject



13
14
15
# File 'lib/ruby-appraiser/appraisal.rb', line 13

def options
  @options.dup
end

#project_rootObject



72
73
74
# File 'lib/ruby-appraiser/appraisal.rb', line 72

def project_root
  @project_root ||= (`git rev-parse --show-toplevel`).chomp
end

#relative_path(path) ⇒ Object



76
77
78
79
# File 'lib/ruby-appraiser/appraisal.rb', line 76

def relative_path(path)
  full_path = File::expand_path(path, project_root)
  full_path[(project_root.length + 1)..-1]
end

#run!Object



17
18
19
20
21
22
23
# File 'lib/ruby-appraiser/appraisal.rb', line 17

def run!
  appraisers.each do |appraiser|
    appraiser.appraise
  end unless relevant_files.empty?

  @has_run = true
end

#source_filesObject



51
52
53
54
55
# File 'lib/ruby-appraiser/appraisal.rb', line 51

def source_files
  Dir::glob(File::expand_path('**/*', project_root)).select do |filepath|
    File::file? filepath and RubyAppraiser::rubytype? filepath
  end.map { |path| relative_path path }
end

#success?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/ruby-appraiser/appraisal.rb', line 25

def success?
  run! unless @has_run

  defects.empty?
end

#summaryObject



68
69
70
# File 'lib/ruby-appraiser/appraisal.rb', line 68

def summary
  "#{defects.count} defects detected."
end

#to_sObject



64
65
66
# File 'lib/ruby-appraiser/appraisal.rb', line 64

def to_s
  defects.to_a.sort.map(&:to_s).join($/)
end