class Minitag::TagRegistry

Stores tags associated with a namespace or a single test case.

A namespace is usually the class which tests belongs to.

Public Class Methods

new() click to toggle source
# File lib/minitag/tag_registry.rb, line 8
def initialize
  @registry = {}
end

Public Instance Methods

add(namespace:, name:, tags:) click to toggle source

Associates tags with a name taking into account its namespace.

Duplicated tags will be removed during this operation.

@param [String] namespace the context which a test name belongs. @param [String] name the test name. @param [Array] tags the collection of tags associated with a test.

@return [void]

# File lib/minitag/tag_registry.rb, line 21
def add(namespace:, name:, tags:)
  @registry[key(namespace, name)] = Set.new(tags)
end
add_for_namespace(namespace:, tags:) click to toggle source

Associates tags with a namespace.

Duplicated tags will be removed during this operation.

@param [String] namespace the context which a test name belongs. @param [Array] tags the collection of tags associated with a test.

@return [void]

# File lib/minitag/tag_registry.rb, line 33
def add_for_namespace(namespace:, tags:)
  @registry[namespace] = Set.new(tags)
end
get(namespace:, name:) click to toggle source

Fetches tags associated with a test name and namespace.

@param [String] namespace the context which a test name belongs. @param [String] name the test name.

@return [Set] the tags associated with the specified namespace and test name.

# File lib/minitag/tag_registry.rb, line 43
def get(namespace:, name:)
  @registry.fetch(namespace, Set.new).union(
    @registry.fetch(key(namespace, name), Set.new)
  )
end

Private Instance Methods

key(namespace, name) click to toggle source
# File lib/minitag/tag_registry.rb, line 51
def key(namespace, name)
  "#{namespace}_#{name}"
end