Class: Cadre::SimpleCov::VimFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/cadre/simplecov/vim-formatter.rb

Defined Under Namespace

Classes: Scope

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options


7
8
9
# File 'lib/cadre/simplecov/vim-formatter.rb', line 7

def options
  @options
end

Instance Method Details

#common_directory(files) ⇒ Object


45
46
47
48
49
50
# File 'lib/cadre/simplecov/vim-formatter.rb', line 45

def common_directory(files)
  return "" if files.empty?
  File::join(files.map{|file| file.split(File::Separator)}.inject do |dir, path|
    dir.zip(path).take_while{|l,r| l == r}.map{|l,_| l}
  end)
end

#format(result) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cadre/simplecov/vim-formatter.rb', line 21

def format(result)
  scope = Scope.new({})
  dir_re = /^#{common_directory(result.filenames)}\//
    result.filenames.zip(result.original_result.values_at(*result.filenames)).each do |name, lines|

    scope.results[name.sub(dir_re, "")] = file_results = {:ignored => [], :hits => [], :misses => []}
    lines.each_with_index do |hits, line|
      case hits
      when nil
        file_results[:ignored] << line + 1
      when 0
        file_results[:misses] << line + 1
      else
        file_results[:hits] << line + 1
      end
    end
    end

  coverage_output = options.output_path

  write_file("coverage-results.vim", coverage_output, scope)
  puts "Wrote vim coverage script to #{coverage_output}" unless options.quiet?
end

#optionsObject


10
11
12
13
14
15
16
17
# File 'lib/cadre/simplecov/vim-formatter.rb', line 10

def options
  @options ||=
    begin
      require 'cadre/config'
      require 'cadre/valise'
      Config.new(Valise, "simplecov")
    end
end

#templatesObject


52
53
54
# File 'lib/cadre/simplecov/vim-formatter.rb', line 52

def templates
  @templates ||= Valise.templates
end

#write_file(template_name, output_filename, bound) ⇒ Object


56
57
58
59
60
61
62
# File 'lib/cadre/simplecov/vim-formatter.rb', line 56

def write_file(template_name, output_filename, bound)
  FileUtils::mkdir_p(File::dirname(output_filename))
  content = templates.find(template_name).contents.render(bound)
  File.open( output_filename, "w" ) do |file_result|
    file_result.write content
  end
end