Class: Minitag::TagRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/minitag/tag_registry.rb

Overview

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

A namespace is usually the class which tests belongs to.

Instance Method Summary collapse

Constructor Details

#initializeTagRegistry

Returns a new instance of TagRegistry.



8
9
10
# File 'lib/minitag/tag_registry.rb', line 8

def initialize
  @registry = {}
end

Instance Method Details

#add(namespace:, name:, tags:) ⇒ void

This method returns an undefined value.

Associates tags with a name taking into account its namespace.

Duplicated tags will be removed during this operation.

Parameters:

  • namespace (String)

    the context which a test name belongs.

  • name (String)

    the test name.

  • tags (Array)

    the collection of tags associated with a test.



21
22
23
# 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:) ⇒ void

This method returns an undefined value.

Associates tags with a namespace.

Duplicated tags will be removed during this operation.

Parameters:

  • namespace (String)

    the context which a test name belongs.

  • tags (Array)

    the collection of tags associated with a test.



33
34
35
# File 'lib/minitag/tag_registry.rb', line 33

def add_for_namespace(namespace:, tags:)
  @registry[namespace] = Set.new(tags)
end

#get(namespace:, name:) ⇒ Set

Fetches tags associated with a test name and namespace.

Parameters:

  • namespace (String)

    the context which a test name belongs.

  • name (String)

    the test name.

Returns:

  • (Set)

    the tags associated with the specified namespace and test name.



43
44
45
46
47
# 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