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(*args) ⇒ Object



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

def add_defect(*args)
  if args.first.kind_of?(Defect)
    defect = args.shift
  else
    file, line, desc = *args
    defect = Defect.new(relative_path(file), line, desc)
  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



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

def project_root
  @project_root ||= RubyAppraiser::Git.project_root
end

#relative_path(path) ⇒ Object



79
80
81
82
# File 'lib/ruby-appraiser/appraisal.rb', line 79

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



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

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

#to_sObject



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

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