module Pluginator::Extensions::FirstClass

Extension to find first plugin whose class matches the string

Public Instance Methods

first_class(type, klass) click to toggle source

Find first plugin whose class matches the given name.

@param type [String] name of type to search for plugins @param klass [Symbol|String] name of the searched class @return [Class] The first plugin that matches the klass

# 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) click to toggle source

Find first plugin whose class matches the given name. Behaves like `first_class` but throws exceptions if can not find anything. @param type [String] name of type to search for plugins @param klass [Symbol|String] name of the searched class @return [Class] The first plugin that matches the klass @raise [Pluginator::MissingPlugin] when can not find plugin

# 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