Class: ReverseCoverage::Main

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/reverse_coverage/main.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMain

Returns a new instance of Main.



12
13
14
15
16
17
# File 'lib/reverse_coverage/main.rb', line 12

def initialize
  @config = {
    file_filter: ->(file_path) { file_of_project?(file_path) }
  }
  @output_path = 'tmp'
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



10
11
12
# File 'lib/reverse_coverage/main.rb', line 10

def config
  @config
end

#coverage_matrixObject (readonly)

Returns the value of attribute coverage_matrix.



9
10
11
# File 'lib/reverse_coverage/main.rb', line 9

def coverage_matrix
  @coverage_matrix
end

#output_pathObject

Returns the value of attribute output_path.



10
11
12
# File 'lib/reverse_coverage/main.rb', line 10

def output_path
  @output_path
end

Class Method Details

.method_missing(method, *args, &block) ⇒ Object



68
69
70
# File 'lib/reverse_coverage/main.rb', line 68

def method_missing(method, *args, &block)
  instance.respond_to?(method) ? instance.send(method, *args, &block) : super
end

.respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/reverse_coverage/main.rb', line 72

def respond_to_missing?(method, include_private = false)
  instance.respond_to?(method) || super
end

Instance Method Details

#add(example) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/reverse_coverage/main.rb', line 19

def add(example)
  coverage_result = Coverage.peek_result
  example_data = slice_attributes(example., *example_attributes)
  example_data[:example_ref] = example_data.hash
  current_state = select_project_files(coverage_result)
  all_changed_files = changed_lines(@last_state, current_state)

  changes = {}

  all_changed_files.each do |file_path, lines|
    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)
    end
  end

  reset_last_state
  changes
end

#reset_last_state(result = Coverage.peek_result) ⇒ Object



43
44
45
# File 'lib/reverse_coverage/main.rb', line 43

def reset_last_state(result = Coverage.peek_result)
  @last_state = select_project_files(result)
end

#result_and_stop_coverageObject



63
64
65
# File 'lib/reverse_coverage/main.rb', line 63

def result_and_stop_coverage
  Coverage.result
end

#save_results(file_name: 'reverse_coverage.yml') ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/reverse_coverage/main.rb', line 52

def save_results(file_name: 'reverse_coverage.yml')
  result_and_stop_coverage
  path = File.join(output_path, file_name)
  FileUtils.mkdir_p(output_path)

  File.open(path, 'w') do |f|
    results = @coverage_matrix.sort.map { |k, v| [k, v.sort.to_h] }.to_h
    f.write results.to_yaml
  end
end

#startObject



47
48
49
50
# File 'lib/reverse_coverage/main.rb', line 47

def start
  @coverage_matrix = {}
  reset_last_state
end