Module: Pork::Isolate

Included in:
Executor
Defined in:
lib/pork/isolate.rb

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



12
13
14
# File 'lib/pork/isolate.rb', line 12

def [] index
  by_groups(index) || by_source(index)
end

#all_pathsObject



8
9
10
# File 'lib/pork/isolate.rb', line 8

def all_paths
  (all_tests[:files] || {}).values.flat_map(&:values).flatten(1).uniq
end

#all_testsObject



4
5
6
# File 'lib/pork/isolate.rb', line 4

def all_tests
  @all_tests ||= build_all_tests
end

#by_groups(groups) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/pork/isolate.rb', line 16

def by_groups groups
  return unless tests = all_tests[:groups]
  paths = groups.split(',').flat_map do |g|
    tests[g.strip] || []
  end.uniq
  paths unless paths.empty?
end

#by_source(source) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pork/isolate.rb', line 24

def by_source source
  return unless tests = all_tests[:files]
  file_str, line_str = source.split(':')
  file, line = File.expand_path(file_str), line_str.to_i
  return unless cases = tests[file]
  if line.zero?
    cases.values.flatten(1).uniq
  else
    _, paths = cases.reverse_each.find{ |(l, _)| l <= line }
    paths
  end
end