Class: Minitag::Context
- Inherits:
-
Object
- Object
- Minitag::Context
- Defined in:
- lib/minitag/context.rb
Overview
Represents the execution context of the test suite.
Instance Method Summary collapse
-
#add_filter(tag) ⇒ void
Adds a filter tag.
-
#add_namespace_tags(namespace:, tags:) ⇒ void
Add tags to an entire namespace.
-
#add_test_tags(namespace:, name:, tags:) ⇒ void
Associates tags with a name taking into account its namespace.
-
#initialize ⇒ Context
constructor
A new instance of Context.
-
#match?(namespace:, name:) ⇒ Boolean
Detects whether the name associated with a namespace contains tags that matches the filtering criteria.
-
#no_filters? ⇒ Boolean
Indicates when a context has no filters.
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 |
# File 'lib/minitag/context.rb', line 8 def initialize @inclusive_filters = Set.new @exclusive_filters = Set.new @tag_registry = Minitag::TagRegistry.new end |
Instance Method Details
#add_filter(tag) ⇒ void
This method returns an undefined value.
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.
47 48 49 50 51 52 53 |
# File 'lib/minitag/context.rb', line 47 def add_filter(tag) if tag.start_with?('~') @exclusive_filters << tag[1..tag.length - 1] else @inclusive_filters << tag end end |
#add_namespace_tags(namespace:, tags:) ⇒ void
This method returns an undefined value.
Add tags to an entire namespace. Every test within the namespace will share these tags.
32 33 34 |
# File 'lib/minitag/context.rb', line 32 def (namespace:, tags:) @tag_registry.add_for_namespace(namespace: namespace, tags: ) end |
#add_test_tags(namespace:, name:, tags:) ⇒ void
This method returns an undefined value.
Associates tags with a name taking into account its namespace.
21 22 23 |
# File 'lib/minitag/context.rb', line 21 def (namespace:, name:, tags:) @tag_registry.add(namespace: namespace, name: name, tags: ) end |
#match?(namespace:, name:) ⇒ Boolean
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?
Invariants:
- Returns true when no filters are present.
74 75 76 77 78 79 |
# File 'lib/minitag/context.rb', line 74 def match?(namespace:, name:) return true if no_filters? = @tag_registry.get(namespace: namespace, name: name) match_inclusive_filters?() && match_exclusive_filters?() end |
#no_filters? ⇒ Boolean
Indicates when a context has no filters.
58 59 60 |
# File 'lib/minitag/context.rb', line 58 def no_filters? @inclusive_filters.empty? && @exclusive_filters.empty? end |