Class: CoverMe::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/cover_me/processor.rb

Overview

Processes the coverage results and then formats them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coverage_results, options = {}) ⇒ Processor

:nodoc:



8
9
10
11
12
13
14
15
16
# File 'lib/cover_me/processor.rb', line 8

def initialize(coverage_results, options = {}) # :nodoc:
  self.coverage_results = coverage_results
  self.options = ({:patterns => CoverMe.config.file_pattern,
                   :exclude_patterns => CoverMe.config.exclude_file_patterns,
                   :formatter => CoverMe.config.formatter.new}.merge(options)).to_mash
  self.index = CoverMe::Index.new
  self.options[:patterns] = [self.options[:patterns]].flatten
  self.options[:exclude_patterns] = [self.options[:exclude_patterns]].flatten
end

Instance Attribute Details

#coverage_resultsObject

Returns the value of attribute coverage_results.



4
5
6
# File 'lib/cover_me/processor.rb', line 4

def coverage_results
  @coverage_results
end

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/cover_me/processor.rb', line 6

def index
  @index
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/cover_me/processor.rb', line 5

def options
  @options
end

Instance Method Details

#process!Object

Processes the coverage results and then formats them. Coverage is only reported if the file matches the pattern defined in the configuration. See the README for more details.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cover_me/processor.rb', line 22

def process!
  self.coverage_results.map do |filename, coverage|
    # next unless filename.match(/#{CoverMe.config.project.root}/)
    exclude = false
    self.options[:exclude_patterns].each do |pattern|
      if filename.match(pattern)
        exclude = true
        break
      end
    end
    next if exclude
    self.options[:patterns].each do |pattern|
      if filename.match(pattern)
        report = CoverMe::Report.new(filename, coverage)
        if report.exists?
          self.index.reports << report
          self.options[:formatter].format(report)
        end
        break
      end
    end
  end
  self.options[:formatter].format(self.index)
  self.options[:formatter].finalize
end