Module: Pluginator::Extensions::Matching

Includes:
Conversions, PluginsMap
Defined in:
lib/plugins/pluginator/extensions/matching.rb

Overview

Extension to select plugins that class name matches the list of string

Instance Method Summary collapse

Methods included from Conversions

#class2name, #class2string, #string2class

Methods included from PluginsMap

#plugins_map

Instance Method Details

#matching(type, list) ⇒ Array

Map array of names to available plugins.

Parameters:

  • type (String)

    name of type to search for plugins

  • list (Array)

    list of plugin names to load

Returns:

  • (Array)

    list of loaded plugins



34
35
36
37
38
# File 'lib/plugins/pluginator/extensions/matching.rb', line 34

def matching(type, list)
  list.map do |plugin|
    (plugins_map(type) || {})[string2class(plugin)]
  end
end

#matching!(type, list) ⇒ Array

Map array of names to available plugins. Behaves like ‘matching` but throws exceptions if can not find anything.

Parameters:

  • type (String)

    name of type to search for plugins

  • list (Array)

    list of plugin names to load

Returns:

  • (Array)

    list of loaded plugins

Raises:



46
47
48
49
50
51
52
53
# File 'lib/plugins/pluginator/extensions/matching.rb', line 46

def matching!(type, list)
  @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys)
  list.map do |plugin|
    plugin = string2class(plugin)
    plugins_map(type)[plugin] or
      raise Pluginator::MissingPlugin.new(type, plugin, plugins_map(type).keys)
  end
end