Class: Coverband::Utils::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/coverband/utils/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_result) ⇒ Result

Initialize a new Coverband::Result from given Coverage.result (a Hash of filenames each containing an array of coverage data)



32
33
34
35
36
37
38
# File 'lib/coverband/utils/result.rb', line 32

def initialize(original_result)
  @original_result = (original_result || {}).freeze

  @files = Coverband::Utils::FileList.new(@original_result.map { |filename, coverage|
    Coverband::Utils::SourceFile.new(filename, coverage) if File.file?(filename)
  }.compact.sort_by(&:short_name))
end

Instance Attribute Details

#created_atObject

Defines when this result has been created. Defaults to Time.now



46
47
48
# File 'lib/coverband/utils/result.rb', line 46

def created_at
  @created_at ||= Time.now
end

#filesObject (readonly) Also known as: source_files

Returns all files that are applicable to this result (sans filters!) as instances of Coverband::SourceFile. Aliased as :source_files



22
23
24
# File 'lib/coverband/utils/result.rb', line 22

def files
  @files
end

#original_resultObject (readonly)

Returns the original Coverage.result used for this instance of Coverband::Result



19
20
21
# File 'lib/coverband/utils/result.rb', line 19

def original_result
  @original_result
end

Class Method Details

.add_not_loaded_files(result, tracked_files) ⇒ Object

Finds files that were to be tracked but were not loaded and initializes the line-by-line coverage to zero (if relevant) or nil (comments / whitespace etc).



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/coverband/utils/result.rb', line 52

def self.add_not_loaded_files(result, tracked_files)
  if tracked_files
    Dir[tracked_files].each do |file|
      absolute = File.expand_path(file)
      result[absolute] ||= {
        "data" => [],
        "never_loaded" => true
      }
    end
  end

  result
end

Instance Method Details

#filenamesObject

Returns all filenames for source files contained in this result



41
42
43
# File 'lib/coverband/utils/result.rb', line 41

def filenames
  files.map(&:filename)
end