class Retest::Repository
Attributes
cache[RW]
files[RW]
input_stream[RW]
output_stream[RW]
Public Class Methods
new(files: [], cache: {}, input_stream: nil, output_stream: nil)
click to toggle source
# File lib/retest/repository.rb, line 5 def initialize(files: [], cache: {}, input_stream: nil, output_stream: nil) @cache = cache @files = files @input_stream = input_stream || STDIN @output_stream = output_stream|| STDOUT end
Public Instance Methods
add(added)
click to toggle source
# File lib/retest/repository.rb, line 29 def add(added) return if added&.empty? files.push(*added) files.sort! end
find_test(path)
click to toggle source
# File lib/retest/repository.rb, line 12 def find_test(path) return unless path return if path.empty? @path = path cache[@path] ||= select_from TestOptions.for(@path, files: files) end
find_tests(paths)
click to toggle source
# File lib/retest/repository.rb, line 20 def find_tests(paths) paths .select { |path| Regexp.new("\.rb$") =~ path } .map { |path| find_test(path) } .compact .uniq .sort end
remove(removed)
click to toggle source
# File lib/retest/repository.rb, line 36 def remove(removed) return if removed&.empty? if removed.is_a?(Array) removed.each { |file| files.delete(file) } else files.delete(removed) end end
Private Instance Methods
ask_question(tests)
click to toggle source
# File lib/retest/repository.rb, line 58 def ask_question(tests) output_stream.puts <<~QUESTION We found few tests matching: #{@path} #{list_options(tests)} Which file do you want to use? Enter the file number now: QUESTION end
get_input()
click to toggle source
# File lib/retest/repository.rb, line 74 def get_input input_stream.gets.chomp.to_i end
list_options(tests)
click to toggle source
# File lib/retest/repository.rb, line 68 def list_options(tests) tests.map.with_index do |file, index| "[#{index}] - #{file}" end.join("\n") end
select_from(tests)
click to toggle source
# File lib/retest/repository.rb, line 48 def select_from(tests) case tests.count when 0, 1 tests.first else ask_question tests tests[get_input] end end