Module: Cuniculus::Plugins

Defined in:
lib/cuniculus/plugins.rb,
lib/cuniculus/plugins/health_check.rb

Overview

Base plugin load and registration module.

Defined Under Namespace

Modules: HealthCheck

Class Method Summary collapse

Class Method Details

.load_plugin(name) ⇒ Module

Method that loads a plugin file. It should not be called directly; instead use Cuniculus.plugin method to add and configure a plugin.

Parameters:

  • name (Symbol)

    name of plugin, also matching its file name.

Returns:

  • (Module)


16
17
18
19
20
21
22
23
# File 'lib/cuniculus/plugins.rb', line 16

def self.load_plugin(name)
  h = @plugins
  unless plugin = h[name]
    require "cuniculus/plugins/#{name}"
    raise Cuniculus::Error, "Plugin was not registered with 'register_plugin'" unless plugin = h[name]
  end
  plugin
end

.register_plugin(name, mod) ⇒ Object

Include plugin module into a Hash so it can be referenced by its name. This method should be called by the plugin itself, so that when it is required (by load_plugin), it can be found.

Examples:

Register a plugin named ‘my_plugin`

# file: my_plugin.rb
module Cuniculus
  module Plugins
    module MyPlugin
    end
    register_plugin(:my_plugin, MyPlugin)
  end
end

Parameters:

  • name (Symbol)

    Name of the plugin, matching its file name.

  • mod (Module)

    The plugin module.



41
42
43
# File 'lib/cuniculus/plugins.rb', line 41

def self.register_plugin(name, mod)
  @plugins[name] = mod
end