Class: Retest::Repository
- Inherits:
-
Object
- Object
- Retest::Repository
- Defined in:
- lib/retest/repository.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#files ⇒ Object
Returns the value of attribute files.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
Instance Method Summary collapse
- #add(added) ⇒ Object
- #find_test(path) ⇒ Object
- #find_tests(paths) ⇒ Object
-
#initialize(files: [], cache: {}, prompt: nil) ⇒ Repository
constructor
A new instance of Repository.
- #remove(removed) ⇒ Object
- #sync(added:, removed:) ⇒ Object
Constructor Details
#initialize(files: [], cache: {}, prompt: nil) ⇒ Repository
Returns a new instance of Repository.
5 6 7 8 9 |
# File 'lib/retest/repository.rb', line 5 def initialize(files: [], cache: {}, prompt: nil) @cache = cache @files = files @prompt = prompt || Prompt.new end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
3 4 5 |
# File 'lib/retest/repository.rb', line 3 def cache @cache end |
#files ⇒ Object
Returns the value of attribute files.
3 4 5 |
# File 'lib/retest/repository.rb', line 3 def files @files end |
#prompt ⇒ Object
Returns the value of attribute prompt.
3 4 5 |
# File 'lib/retest/repository.rb', line 3 def prompt @prompt end |
Instance Method Details
#add(added) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/retest/repository.rb', line 39 def add(added) return if added&.empty? files.push(*added) files.sort! end |
#find_test(path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/retest/repository.rb', line 11 def find_test(path) return unless path return if path.empty? unless cache.key?(path) ok_to_cache, test_file = select_from path, MatchingOptions.for(path, files: files) if ok_to_cache cache[path] = test_file end end cache[path] end |
#find_tests(paths) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/retest/repository.rb', line 25 def find_tests(paths) paths .select { |path| Regexp.new("\.rb$") =~ path } .map { |path| find_test(path) } .compact .uniq .sort end |
#remove(removed) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/retest/repository.rb', line 46 def remove(removed) return if removed&.empty? if removed.is_a?(Array) removed.each { |file| files.delete(file) } else files.delete(removed) end end |
#sync(added:, removed:) ⇒ Object
34 35 36 37 |
# File 'lib/retest/repository.rb', line 34 def sync(added:, removed:) add(added) remove(removed) end |