Class: Slather::CoverageFile
- Inherits:
-
Object
- Object
- Slather::CoverageFile
- Defined in:
- lib/slather/coverage_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#gcno_file_pathname ⇒ Object
Returns the value of attribute gcno_file_pathname.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
- #coverage_for_line(line) ⇒ Object
- #gcov_data ⇒ Object
-
#initialize(gcno_file_pathname) ⇒ CoverageFile
constructor
A new instance of CoverageFile.
- #source_data ⇒ Object
- #source_file ⇒ Object
- #source_file_pathname ⇒ Object
- #source_file_pathname_relative_to_project_root ⇒ Object
Constructor Details
#initialize(gcno_file_pathname) ⇒ CoverageFile
Returns a new instance of CoverageFile.
6 7 8 |
# File 'lib/slather/coverage_file.rb', line 6 def initialize(gcno_file_pathname) @gcno_file_pathname = Pathname(gcno_file_pathname) end |
Instance Attribute Details
#gcno_file_pathname ⇒ Object
Returns the value of attribute gcno_file_pathname.
4 5 6 |
# File 'lib/slather/coverage_file.rb', line 4 def gcno_file_pathname @gcno_file_pathname end |
#project ⇒ Object
Returns the value of attribute project.
4 5 6 |
# File 'lib/slather/coverage_file.rb', line 4 def project @project end |
Instance Method Details
#coverage_for_line(line) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/slather/coverage_file.rb', line 46 def coverage_for_line(line) line =~ /^(.+?):/ match = $1.strip case match when /[0-9]+/ match.to_i when /#+/ 0 when "-" nil end end |
#gcov_data ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/slather/coverage_file.rb', line 31 def gcov_data @gcov_data ||= begin gcov_output = `gcov #{source_file_pathname} --object-directory #{gcno_file_pathname.parent}` # Sometimes gcov makes gcov files for Cocoa Touch classes, like NSRange. Ignore and delete later. gcov_files_created = gcov_output.scan(/creating '(.+\..+\.gcov)'/) gcov_file = File.new("./#{source_file_pathname.basename}.gcov") gcov_data = gcov_file.read gcov_files_created.each { |file| FileUtils.rm(file) } gcov_data end end |
#source_data ⇒ Object
23 24 25 |
# File 'lib/slather/coverage_file.rb', line 23 def source_data source_file.read end |
#source_file ⇒ Object
19 20 21 |
# File 'lib/slather/coverage_file.rb', line 19 def source_file File.new(source_file_pathname) end |
#source_file_pathname ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/slather/coverage_file.rb', line 10 def source_file_pathname @source_file_pathname ||= begin base_filename = gcno_file_pathname.basename.sub_ext("") # TODO: Handle Swift path = Dir["#{project.main_group.real_path}/*/#{base_filename}.m"].first path && Pathname(path) end end |
#source_file_pathname_relative_to_project_root ⇒ Object
27 28 29 |
# File 'lib/slather/coverage_file.rb', line 27 def source_file_pathname_relative_to_project_root source_file_pathname.relative_path_from(project.main_group.real_path) end |