Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/reverse_coverage/formatters/html/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,42 @@ def formatted_source_file(source_file)
end

def readfile(source_file)
File.open(filename(source_file), "rb", &:readlines)
load_source(filename(source_file))
end

def load_source(file_name)
lines = []
# The default encoding is UTF-8
File.open(file_name, "rb:UTF-8") do |file|
line = file.gets

# Check for shbang
if /\A#!/.match?(line)
lines << line
line = file.gets
end
return lines unless line

check_magic_comment(file, line)
lines.concat([line], file.readlines)
end

lines
end

def check_magic_comment(file, line)
# Check for encoding magic comment
# Encoding magic comment must be placed at first line except for shbang
if (match = /\A#\s*(?:-\*-)?\s*(?:en)?coding:\s*(\S+)\s*(?:-\*-)?\s*\z/.match(line))
file.set_encoding(match[1], "UTF-8")
end
end

def grouped(files)
grouped = {}
grouped_files = []

# TODO Someday / Maybe. Make this list configurable
groups = {
'Controllers' => %r{/app/controllers},
'Channels' => %r{/app/channels},
Expand Down
6 changes: 2 additions & 4 deletions lib/reverse_coverage/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def add(example)
lines.each_with_index do |changed, line_index|
next if changed.nil? || changed.zero?

file_info = { file_path: file_path, line_index: line_index }

save_changes(changes, example_data, file_info)
save_changes(coverage_matrix, example_data, file_info)
save_changes(changes, example_data, file_path: file_path, line_index: line_index)
save_changes(coverage_matrix, example_data, file_path: file_path, line_index: line_index)
end
end

Expand Down