Class: RubyAppraiser::Appraisal
- Inherits:
-
Object
- Object
- RubyAppraiser::Appraisal
- Defined in:
- lib/ruby-appraiser/appraisal.rb
Instance Method Summary collapse
- #adapters ⇒ Object
- #add_adapter(name) ⇒ Object
- #add_defect(*args) ⇒ Object
- #appraisers ⇒ Object
- #defects ⇒ Object
-
#initialize(options = {}) ⇒ Appraisal
constructor
A new instance of Appraisal.
- #mode ⇒ Object
- #options ⇒ Object
- #project_root ⇒ Object
- #relative_path(path) ⇒ Object
- #run! ⇒ Object
- #source_files ⇒ Object
- #success? ⇒ Boolean
- #summary ⇒ Object
- #to_s ⇒ Object
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 = .dup.freeze end |
Instance Method Details
#adapters ⇒ Object
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 |
#appraisers ⇒ Object
39 40 41 42 43 |
# File 'lib/ruby-appraiser/appraisal.rb', line 39 def appraisers adapters.map do |adapter| adapter.new(self, ) end end |
#defects ⇒ Object
31 32 33 |
# File 'lib/ruby-appraiser/appraisal.rb', line 31 def defects @defects ||= Set.new end |
#mode ⇒ Object
9 10 11 |
# File 'lib/ruby-appraiser/appraisal.rb', line 9 def mode @options.fetch(:mode) { 'all' } end |
#options ⇒ Object
13 14 15 |
# File 'lib/ruby-appraiser/appraisal.rb', line 13 def @options.dup end |
#project_root ⇒ Object
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::(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_files ⇒ Object
51 52 53 54 55 |
# File 'lib/ruby-appraiser/appraisal.rb', line 51 def source_files Dir::glob(File::('**/*', project_root)).select do |filepath| File::file? filepath and RubyAppraiser::rubytype? filepath end.map { |path| relative_path path } end |
#success? ⇒ Boolean
25 26 27 28 29 |
# File 'lib/ruby-appraiser/appraisal.rb', line 25 def success? run! unless @has_run defects.empty? end |
#summary ⇒ Object
71 72 73 |
# File 'lib/ruby-appraiser/appraisal.rb', line 71 def summary "#{defects.count} defects detected." end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/ruby-appraiser/appraisal.rb', line 67 def to_s defects.to_a.sort.map(&:to_s).join($/) end |