Module: Docscribe::Plugin::Registry

Defined in:
lib/docscribe/plugin/registry.rb

Overview

Global plugin registry.

Plugins are registered once at boot time (e.g. in a file loaded via ‘plugins.require:` in docscribe.yml) and called for every file Docscribe processes.

Thread safety: registration is expected to happen before any parallel rewriting begins.

Class Method Summary collapse

Class Method Details

.clear!void

Note:

module_function: when included, also defines #clear! (instance visibility: private)

This method returns an undefined value.

Remove all registered plugins.

Primarily used in tests to reset state between examples.



63
64
65
66
# File 'lib/docscribe/plugin/registry.rb', line 63

def clear!
  @tag_plugins.clear
  @collector_plugins.clear
end

.collector_pluginsArray<#collect>

Note:

module_function: when included, also defines #collector_plugins (instance visibility: private)

All registered collector plugins in registration order.

Returns:

  • (Array<#collect>)


53
54
55
# File 'lib/docscribe/plugin/registry.rb', line 53

def collector_plugins
  @collector_plugins.dup
end

.register(plugin) ⇒ void

Note:

module_function: when included, also defines #register (instance visibility: private)

This method returns an undefined value.

Register a plugin.

Routes to the appropriate list based on plugin type:

  • subclass of Base::TagPlugin => tag plugin

  • subclass of Base::CollectorPlugin => collector plugin

  • responds to #call => tag plugin (duck typing)

  • responds to #collect => collector plugin (duck typing)

Parameters:

  • plugin (Object)

    plugin instance

Raises:

  • (ArgumentError)

    if plugin type cannot be determined



31
32
33
34
35
36
37
38
39
# File 'lib/docscribe/plugin/registry.rb', line 31

def register(plugin)
  if plugin.is_a?(Base::CollectorPlugin) || plugin.respond_to?(:collect)
    @collector_plugins << plugin
  elsif plugin.is_a?(Base::TagPlugin) || plugin.respond_to?(:call)
    @tag_plugins << plugin
  else
    raise ArgumentError, 'Plugin must respond to #call (TagPlugin) or #collect (CollectorPlugin)'
  end
end

.tag_pluginsArray<#call>

Note:

module_function: when included, also defines #tag_plugins (instance visibility: private)

All registered tag plugins in registration order.

Returns:

  • (Array<#call>)


45
46
47
# File 'lib/docscribe/plugin/registry.rb', line 45

def tag_plugins
  @tag_plugins.dup
end