Class: TraceViz::Context::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/trace_viz/context/registry.rb

Constant Summary collapse

CONTEXTS =
{
  config: ConfigContext,
  tracking: TrackingContext,
}.freeze

Class Method Summary collapse

Class Method Details

.build(contexts) ⇒ Hash

Builds a hash of context objects based on the provided contexts hash.

Parameters:

  • contexts (Hash)

    A hash where the keys are context keys and the values are options for each context. Example:

    {
      context_key1: { option1: 'value1', option2: 'value2' },
      context_key2: { option1: 'value3', option2: 'value4' }
    }
    

Returns:

  • (Hash)

    A hash where the keys are context keys and the values are instantiated context objects.

Raises:

  • (ArgumentError)

    If a context key is not found in the CONTEXTS hash.



27
28
29
30
31
32
33
# File 'lib/trace_viz/context/registry.rb', line 27

def build(contexts)
  contexts.each_with_object({}) do |(context_key, options), result|
    klass = CONTEXTS.fetch(context_key)

    result[context_key] = klass.new(**(options || {}))
  end
end