Class: Judges::Categories
Overview
Categories of tests.
This class manages test categories, allowing you to enable or disable specific categories of tests. It provides a mechanism to filter which tests should be executed based on their associated categories.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(enable, disable) ⇒ Categories
constructor
Initialize a new Categories instance.
-
#ok?(cats) ⇒ Boolean
Check if a test with given categories should be executed.
Constructor Details
#initialize(enable, disable) ⇒ Categories
Initialize a new Categories instance.
Creates a categories filter with lists of enabled and disabled categories. The filter logic works as follows:
-
If a category is in the disable list, the test is rejected
-
If a category is in the enable list, the test is accepted
-
If no categories are enabled (empty enable list), all tests are accepted unless explicitly disabled
29 30 31 32 |
# File 'lib/judges/categories.rb', line 29 def initialize(enable, disable) @enable = enable.is_a?(Array) ? enable : [] @disable = disable.is_a?(Array) ? disable : [] end |
Instance Method Details
#ok?(cats) ⇒ Boolean
Check if a test with given categories should be executed.
Determines whether a test associated with the provided categories should be executed based on the enable/disable lists configured during initialization.
The evaluation logic:
-
If any category is in the disable list, returns false
-
If any category is in the enable list, returns true
-
If the enable list is empty, returns true (all tests allowed)
-
Otherwise, returns false
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/judges/categories.rb', line 54 def ok?(cats) cats = [] if cats.nil? cats = [cats] unless cats.is_a?(Array) cats.each do |c| return false if @disable.any?(c) return true if @enable.any?(c) end return true if @enable.empty? false end |