Module: Pluginator::Extensions::FirstClass

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

Overview

Extension to find first plugin that class matches the string

Instance Method Summary collapse

Methods included from Conversions

#class2name, #class2string, #string2class

Methods included from PluginsMap

#plugins_map

Instance Method Details

#first_class(type, klass) ⇒ Class

Find first plugin that clas matches the given name.

Parameters:

  • type (String)

    name of type to search for plugins

  • klass (Symbol|String)

    name of the searched class

Returns:

  • (Class)

    The first plugin that matches the klass



35
36
37
# File 'lib/plugins/pluginator/extensions/first_class.rb', line 35

def first_class(type, klass)
  (plugins_map(type) || {})[string2class(klass)]
end

#first_class!(type, klass) ⇒ Class

Find first plugin that clas matches the given name. Behaves like ‘first_class` but throws exceptions if can not find anything.

Parameters:

  • type (String)

    name of type to search for plugins

  • klass (Symbol|String)

    name of the searched class

Returns:

  • (Class)

    The first plugin that matches the klass

Raises:



45
46
47
48
49
50
# File 'lib/plugins/pluginator/extensions/first_class.rb', line 45

def first_class!(type, klass)
  @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys)
  klass = string2class(klass)
  plugins_map(type)[klass] or
    raise Pluginator::MissingPlugin.new(type, klass, plugins_map(type).keys)
end