Class: GCOV::Project
- Inherits:
-
Object
- Object
- GCOV::Project
- Defined in:
- lib/project.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#name ⇒ Object
Returns the value of attribute name.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Class Method Summary collapse
-
.load_dir(path, hash = {}) ⇒ Object
#add_file.
Instance Method Summary collapse
- #<<(file) ⇒ Object
- #_add_file(path, hash_ = {}) ⇒ Object
- #_update_stats ⇒ Object
- #add_dir(path, hash_ = {}) ⇒ Object
-
#add_file(path, hash_ = {}) ⇒ Object
#add_dir.
- #add_files(&block) ⇒ Object
-
#initialize(name = "") ⇒ Project
constructor
A new instance of Project.
Constructor Details
#initialize(name = "") ⇒ Project
Returns a new instance of Project.
12 13 14 15 16 |
# File 'lib/project.rb', line 12 def initialize name="" @name = name @files = {} @adding = false end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
9 10 11 |
# File 'lib/project.rb', line 9 def files @files end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/project.rb', line 10 def name @name end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
9 10 11 |
# File 'lib/project.rb', line 9 def stats @stats end |
Class Method Details
Instance Method Details
#<<(file) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/project.rb', line 18 def <<(file) if @files.has_key?file.name @files[file.name].merge! file else @files[file.name] = file end _update_stats unless @adding end |
#_add_file(path, hash_ = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/project.rb', line 87 def _add_file path, hash_={} hash = hash_.dup # legacy support if !hash[:filter].nil? and ( hash[:filter].is_a? Regexp ) hash[:filter] = [ hash[:filter] ] end files = GCOV::File.load(path) GCOV::logger.info "filters: #{hash[:filter]}" files.each do |file| if hash[:filter].nil? or hash[:filter].empty? or hash[:filter].select{|f| f.match(::Pathname.new(file.['Source']).cleanpath.to_s) }.empty? GCOV::logger.info "+ adding: #{::Pathname.new(file.['Source']).cleanpath.to_s}" self << file else GCOV::logger.info "- skipping: #{::Pathname.new(file.['Source']).cleanpath.to_s}" end # if end #each file end |
#_update_stats ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/project.rb', line 52 def _update_stats @stats = { :missed_lines => 0, :exec_lines => 0, :empty_lines => 0, :total_exec => 0, :total_lines => 0, :lines => 0, :coverage => 0.0, :hits_per_line => 0 } @files.each do |name,file| @stats[:missed_lines] += file.stats[:missed_lines] @stats[:exec_lines] += file.stats[:exec_lines] @stats[:total_exec] += file.stats[:total_exec] @stats[:empty_lines] += file.stats[:empty_lines] end @stats[:lines] = @stats[:exec_lines] + @stats[:missed_lines] @stats[:total_lines] = @stats[:lines] + @stats[:empty_lines] if @stats[:lines] > 0 @stats[:coverage] = @stats[:exec_lines].to_f / @stats[:lines].to_f @stats[:hits_per_line] = @stats[:total_exec].to_f / @stats[:lines] else @stats[:coverage] = 1 @stats[:hits_per_line] = 0 end @stats[:coverage_s] = sprintf("%0.01f%",100.0*@stats[:coverage]) @stats[:hits_per_line_s] = sprintf("%0.02f",@stats[:hits_per_line]) end |
#add_dir(path, hash_ = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/project.rb', line 109 def add_dir path, hash_={} hash = hash_.dup if hash[:recursive] == true filenames = Dir["#{path}/**/*.gcov"] else filenames = Dir["#{path}/*.gcov"] end add_files do filenames.each do |filename| _add_file filename, hash end # each filename end # add_files end |
#add_file(path, hash_ = {}) ⇒ Object
#add_dir
124 125 126 127 128 129 |
# File 'lib/project.rb', line 124 def add_file path, hash_={} hash = hash_.dup add_files do _add_file path, hash end # add_files end |
#add_files(&block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/project.rb', line 38 def add_files &block # suspend stat updates until done adding files fail "add_files requires a block" unless block_given? # guard against nested calls was_adding = @adding @adding = true yield @adding = was_adding _update_stats unless @adding end |