class Retest::TestOptions

Attributes

files[R]
path[R]

Public Class Methods

for(path, files: []) click to toggle source
# File lib/retest/test_options.rb, line 5
def self.for(path, files: [])
  new(path, files: files).filtered_results
end
new(path, files: []) click to toggle source
# File lib/retest/test_options.rb, line 11
def initialize(path, files: [])
  @path = Path.new(path)
  @files = files
end

Public Instance Methods

filtered_results() click to toggle source
# File lib/retest/test_options.rb, line 16
def filtered_results
  if path.test?
    [path]
  elsif namespace_screens.any?
    namespace_screens
  else
    possible_tests
  end.map(&:to_s)
end

Private Instance Methods

filter_by_string_similarities(path, files) click to toggle source
# File lib/retest/test_options.rb, line 34
def filter_by_string_similarities(path, files)
  files.select  { |file| path.possible_test?(file) }
       .sort_by { |file| [path.similarity_score(file), file] }
end
namespace_screens() click to toggle source
# File lib/retest/test_options.rb, line 39
def namespace_screens
  @namespace_screens ||= path
    .reversed_dirnames
    .each_with_index
    .with_object(possible_tests.map { |file| Path.new(file) }) do |(reference, index), result|
      unless [1, 0].include? result.count
        result.keep_if { |path| path.reversed_dirnames[index] == reference }
      end
    end
end
possible_tests() click to toggle source
# File lib/retest/test_options.rb, line 28
def possible_tests
  @possible_tests ||= filter_by_string_similarities(path, files)
    .last(5)
    .reverse
end