class Minitag::Context
Represents the execution context of the test suite.
Public Class Methods
# File lib/minitag/context.rb, line 8 def initialize @inclusive_filters = Set.new @exclusive_filters = Set.new @tag_registry = Minitag::TagRegistry.new end
Public Instance Methods
Adds a filter tag.
Tags with a ~ prefix are treated as exclusive filters or inclusive filters otherwise.
param [String] name the name of the filter tag.
Invariants:
- A filter will always be a String without the ~ prefix.
@return [void]
# File lib/minitag/context.rb, line 47 def add_filter(tag) if tag.start_with?('~') @exclusive_filters << tag[1..] else @inclusive_filters << tag end end
Detects whether the name associated with a namespace contains tags that matches the filtering criteria. For more information check the methods:
- match_inclusive_filters? - match_exclusive_filters?
@param [String] namespace the namespace which a test name belongs. @param [String] name the test name.
Invariants:
- Returns true when no filters are present.
@return [Boolean] whether there was a match or not.
# File lib/minitag/context.rb, line 74 def match?(namespace:, name:) return true if no_filters? tags = @tag_registry.get(namespace: namespace, name: name) match_inclusive_filters?(tags) && match_exclusive_filters?(tags) end
Indicates when a context has no filters.
@return [Boolean] whether a context has no filters.
# File lib/minitag/context.rb, line 58 def no_filters? @inclusive_filters.empty? && @exclusive_filters.empty? end
Private Instance Methods
Detects whether any of the tags matches the exclusive filters.
@param [Set] tags the set of tags.
Invariants:
- Returns true when no exclusive filters are specified. - Returns true when exclusive filters are specified and there are no tags.
return [Boolean] whether there was a match or not.
# File lib/minitag/context.rb, line 110 def match_exclusive_filters?(tags) return true if @exclusive_filters.empty? return true if @exclusive_filters.any? && tags.empty? (@exclusive_filters & tags).none? end
Detects whether any of the tags matches the inclusive filters.
@param [Set] tags the set of tags.
Invariants:
- Returns true when no inclusive filters are specified. - Returns false when inclusive filters are specified but there are no tags.
@return [Boolean] whether there was a match or not.
# File lib/minitag/context.rb, line 93 def match_inclusive_filters?(tags) return true if @inclusive_filters.empty? return false if @inclusive_filters.any? && tags.empty? (@inclusive_filters & tags).any? end