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

#class2string, #string2class

Methods included from PluginsMap

#plugins_map

Instance Method Details

#first_class(type, klass) ⇒ Object

Find first plugin that clas matches the given name.

Parameters:

  • type (String)

    name of type to search for plugins

  • klass (Symbol or String)

    name of the searched class

Returns:

  • The first plugin that matches the klass



16
17
18
# File 'lib/plugins/pluginator/extensions/first_class.rb', line 16

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

#first_class!(type, klass) ⇒ Object

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



22
23
24
25
26
27
# File 'lib/plugins/pluginator/extensions/first_class.rb', line 22

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