Class: Ductr::Registry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ductr/registry.rb

Overview

The registry pattern to store adapters, controls and triggers.

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Registry

Initialize the registry as an empty hash with the given name.

Parameters:

  • name (Symbol)

    The registry name, used in error message



24
25
26
27
# File 'lib/ductr/registry.rb', line 24

def initialize(name)
  @name = name
  @items = {}
end

Instance Method Details

#add(item, as:) ⇒ void

This method returns an undefined value.

Allow to add one class into the registry.

Parameters:

  • item (Class<Adapter, ETL::Control, Trigger>)

    The class to add in the registry

  • as: (Symbol)

    The adapter, control or trigger type



37
38
39
# File 'lib/ductr/registry.rb', line 37

def add(item, as:)
  @items[as.to_sym] = item
end

#find(type) ⇒ Class<Adapter, ETL::Control, Trigger>

Find an adapter, control or trigger based on its type.

Parameters:

  • type (Symbol)

    The adapter, control or trigger type

Returns:

Raises:



49
50
51
52
53
# File 'lib/ductr/registry.rb', line 49

def find(type)
  @items.fetch(type.to_sym) do
    raise NotFoundInRegistryError, "The #{@name} of type \"#{type}\" does not exist"
  end
end

#valuesArray<Class<Adapter, ETL::Control, Trigger>>

Get all registered adapters, controls or triggers.

Returns:



17
# File 'lib/ductr/registry.rb', line 17

def_delegators :@items, :values