Module: Couve

Defined in:
lib/couve.rb,
lib/couve/parser.rb,
lib/couve/version.rb

Defined Under Namespace

Classes: Parser

Constant Summary collapse

VERSION =
"0.7.0"

Class Method Summary collapse

Class Method Details

.changed_files(source) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/couve.rb', line 33

def self.changed_files(source)
  return nil unless source

  contents = source == "-" ? $stdin.read : File.read(source)

  contents.lines.map { |line| line.strip.delete_prefix("./") }.reject(&:empty?)
end

.parse_arguments(argv) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/couve.rb', line 20

def self.parse_arguments(argv)
  argv = argv.dup
  changed_files_source = nil

  OptionParser.new do |opts|
    opts.on("--changed-files PATH", "Only report the files listed in PATH (use - for stdin)") do |path|
      changed_files_source = path
    end
  end.parse!(argv)

  [argv[0], argv[1], changed_files_source]
end

.start(argv = ARGV) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/couve.rb', line 9

def self.start(argv = ARGV)
  coverage_file, output_file, changed_files_source = parse_arguments(argv)

  coverage = File.read(coverage_file)
  parser = Couve::Parser.new(coverage, changed_files: changed_files(changed_files_source))

  report = output_file.end_with?(".md") ? parser.to_markdown : parser.to_html

  File.open(output_file, "w") { |f| f.puts report }
end