Class: Covered::PartialSummary

Inherits:
Summary
  • Object
show all
Defined in:
lib/covered/summary.rb

Instance Method Summary collapse

Methods inherited from Summary

#each, #initialize, #print_annotations

Constructor Details

This class inherits a constructor from Covered::Summary

Instance Method Details

#call(wrapper, output = $stdout, before: 4, after: 4) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/covered/summary.rb', line 127

def call(wrapper, output = $stdout, before: 4, after: 4)
	statistics = self.each(wrapper) do |coverage|
		line_offset = 1
		
		path = wrapper.relative_path(coverage.path)
		output.puts "", Rainbow(path).bold.underline
		
		counts = coverage.counts
		last_line = nil
		
		unless coverage.zero?
			coverage.read do |file|
				file.each_line do |line|
					range = Range.new([line_offset - before, 0].max, line_offset+after)
					
					if counts[range]&.include?(0)
						count = counts[line_offset]
						
						if last_line and last_line != line_offset-1
							output.puts ":".rjust(16)
						end
						
						print_annotations(output, coverage, line, line_offset)
						
						prefix = "#{line_offset}|".rjust(8) + "#{count}|".rjust(8)
						
						if count == nil
							output.write prefix
							output.write Rainbow(line).faint
						elsif count == 0
							output.write Rainbow(prefix).background(:darkred)
							output.write Rainbow(line).red
						else
							output.write Rainbow(prefix).background(:darkgreen)
							output.write Rainbow(line).green
						end
						
						# If there was no newline at end of file, we add one:
						unless line.end_with? $/
							output.puts
						end
						
						last_line = line_offset
					end
					
					line_offset += 1
				end
			end
		end
		
		coverage.print(output)
	end
	
	output.puts
	statistics.print(output)
end