Class: Sus::Filter
- Inherits:
-
Object
- Object
- Sus::Filter
- Defined in:
- lib/sus/filter.rb
Overview
Provides a way to filter the registry according to the suffix on loaded paths.
A test has an identity, e.g. the file and line number on which it’s defined.
A filter takes an identity, decomposes it into a file and suffix, loads the file, and registers the filter suffix.
When the filter is used to enumerate the registry, it will only return the tests that match the suffix.
Defined Under Namespace
Classes: Index
Instance Method Summary collapse
- #call(assertions = Assertions.default) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(registry = Registry.new) ⇒ Filter
constructor
A new instance of Filter.
- #load(target) ⇒ Object
Constructor Details
Instance Method Details
#call(assertions = Assertions.default) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sus/filter.rb', line 75 def call(assertions = Assertions.default) if @keys.any? @index = Index.new @index.add(@registry) @keys.each do |key| @index[key]&.call(assertions) end else @registry.call(assertions) end return assertions end |
#each(&block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sus/filter.rb', line 60 def each(&block) if @keys.any? @index = Index.new @index.add(@registry) @keys.each do |key| if target = @index[key] yield target end end else @registry.each(&block) end end |
#load(target) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/sus/filter.rb', line 50 def load(target) path, filter = target.split(":", 2) @registry.load(path) if filter @keys << target end end |