Module: Archsight::Import::Registry

Defined in:
lib/archsight/import/registry.rb

Overview

Registry of import handlers

Handlers register themselves with a name that matches the import/handler annotation. The executor looks up handlers by name to instantiate and execute them.

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Class?

Look up a handler class by name

Parameters:

  • name (String)

    Handler name

Returns:

  • (Class, nil)

    Handler class or nil if not found



23
24
25
# File 'lib/archsight/import/registry.rb', line 23

def [](name)
  @handlers[name.to_s]
end

.clear!Object

Clear all registered handlers (for testing)



47
48
49
# File 'lib/archsight/import/registry.rb', line 47

def clear!
  @handlers = {}
end

.handler_for(import_resource) ⇒ Class

Get handler class for an import resource

Parameters:

Returns:

  • (Class)

    Handler class

Raises:



31
32
33
34
35
36
37
38
# File 'lib/archsight/import/registry.rb', line 31

def handler_for(import_resource)
  handler_name = import_resource.annotations["import/handler"]
  handler_class = self[handler_name]

  raise Archsight::Import::UnknownHandlerError, "Unknown import handler: #{handler_name}" unless handler_class

  handler_class
end

.handlersArray<String>

List all registered handler names

Returns:

  • (Array<String>)

    Handler names



42
43
44
# File 'lib/archsight/import/registry.rb', line 42

def handlers
  @handlers.keys
end

.register(name, handler_class) ⇒ Object

Register a handler class with a name

Parameters:

  • name (String, Symbol)

    Handler name (matches import/handler annotation)

  • handler_class (Class)

    Handler class that extends Handler



16
17
18
# File 'lib/archsight/import/registry.rb', line 16

def register(name, handler_class)
  @handlers[name.to_s] = handler_class
end