Class: Cucumber::Blanket::CoverageData

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/blanket/coverage_data.rb

Overview

Contains the blanketJS data structure primary purpose is to accumulate more of this data, flattening the structure against multiple runs of fresh data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCoverageData

Returns a new instance of CoverageData.



10
11
12
# File 'lib/cucumber/blanket/coverage_data.rb', line 10

def initialize
  @data = {'files'=>{}}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



14
15
16
# File 'lib/cucumber/blanket/coverage_data.rb', line 14

def method_missing *args
  @data.send(*args)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/cucumber/blanket/coverage_data.rb', line 8

def data
  @data
end

Instance Method Details

#accrue!(page_data) ⇒ Object



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
47
48
49
50
51
52
53
54
# File 'lib/cucumber/blanket/coverage_data.rb', line 22

def accrue! page_data
  if @data.nil?
    @data = page_data
  else
    # for files in page_data ...
    page_data['files'].each do |filename, linedata|
      # that exist in @data
      if @data['files'][filename]
        # accrue coverage data, meaning:
        # get a handle on existing linedata and iterate
        @data['files'][filename].each_with_index do |cov_stat, line_no|
          new_cov_stat = page_data['files'][filename][line_no]
          # first we need to deal with nils, as we cannot add them
          # either side can be nil -- and we want to be strictly additive
          next if new_cov_stat.nil? # this is not additive, next line
          # So now we know the new data is definitely not nil
          # but the existing data could be, so we'll handle that now
          if cov_stat.nil?
            @data['files'][filename][line_no] = new_cov_stat
            # We replaced it with the new data, next line please
            next
          end
          # if we ever get here, we're dealing strictly with integers
          # as a result we just need to sum the two stats
          @data['files'][filename][line_no] = cov_stat + new_cov_stat
        end
      else # if it does not exist
        # add it to 'files' as is
        @data['files'][filename] = linedata
      end
    end
  end
end

#filesObject



18
19
20
# File 'lib/cucumber/blanket/coverage_data.rb', line 18

def files
  self.data['files']
end