Class: AffectedTests::Engine::Rotoscope

Inherits:
Object
  • Object
show all
Defined in:
lib/affected_tests/engine/rotoscope.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Rotoscope

Returns a new instance of Rotoscope.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/affected_tests/engine/rotoscope.rb', line 6

def initialize(config)
  @config = config

  @rotoscope = ::Rotoscope.new do |call|
    next if self == call.receiver

    if call.caller_path && @config.target_path?(call.caller_path)
      buffer << call.caller_path
    end
  end
  @rotoscope.start_trace
end

Instance Method Details

#add(caller, callee) ⇒ Object



54
55
56
57
# File 'lib/affected_tests/engine/rotoscope.rb', line 54

def add(caller, callee)
  cache[callee] ||= Set.new
  cache[callee].add(caller)
end

#bufferObject



59
60
61
# File 'lib/affected_tests/engine/rotoscope.rb', line 59

def buffer
  Thread.current[:buffer] ||= []
end

#cacheObject



63
64
65
# File 'lib/affected_tests/engine/rotoscope.rb', line 63

def cache
  Thread.current[:cache] ||= {}
end

#checkpoint(target_test_path) ⇒ Object



32
33
34
35
36
# File 'lib/affected_tests/engine/rotoscope.rb', line 32

def checkpoint(target_test_path)
  diff = buffer
  import(target_test_path, diff)
  buffer.clear
end

#dumpObject



67
68
69
70
# File 'lib/affected_tests/engine/rotoscope.rb', line 67

def dump
  @rotoscope.stop_trace
  cache.transform_values(&:to_a)
end

#import(target_test_path, result) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/affected_tests/engine/rotoscope.rb', line 38

def import(target_test_path, result)
  all_related_paths = result.uniq.map do |caller_path|
    @config.format_path(caller_path)
  end

  formatted_target_test_path = @config.format_path(target_test_path)

  all_related_paths.each do |path|
    next if path.start_with?(@config.test_dir_path)

    if path != formatted_target_test_path
      add(formatted_target_test_path, path)
    end
  end
end

#start_traceObject



19
20
21
22
# File 'lib/affected_tests/engine/rotoscope.rb', line 19

def start_trace
  # Clear buffer
  buffer.clear
end

#stop_traceObject



24
25
26
# File 'lib/affected_tests/engine/rotoscope.rb', line 24

def stop_trace
  # do nothing
end

#tracing?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/affected_tests/engine/rotoscope.rb', line 28

def tracing?
  @rotoscope.tracing?
end