Module: Pluginator::Extensions::FirstAsk

Includes:
PluginsMap
Defined in:
lib/plugins/pluginator/extensions/first_ask.rb

Overview

Extension to find first plugin that answers the question with true

Instance Method Summary collapse

Methods included from PluginsMap

#plugins_map

Methods included from Conversions

#class2name, #class2string, #string2class

Instance Method Details

#first_ask(type, method_name, *params) ⇒ Class

Call a method on plugin and return first one that returns ‘true`.

Parameters:

  • type (String)

    name of type to search for plugins

  • method_name (Symbol)

    name of the method to execute

  • params (Array)

    params to pass to the called method

Returns:

  • (Class)

    The first plugin that method call returns true



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

def first_ask(type, method_name, *params)
  @plugins[type] or return nil
  try_to_find(type, method_name, params)
end

#first_ask!(type, method_name, *params) ⇒ Class

Call a method on plugin and return first one that returns ‘true`. Behaves like `first_ask` but throws exceptions if can not find anything.

Parameters:

  • type (String)

    name of type to search for plugins

  • method_name (Symbol)

    name of the method to execute

  • params (Array)

    params to pass to the called method

Returns:

  • (Class)

    The first plugin that method call returns true

Raises:



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

def first_ask!(type, method_name, *params)
  @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys)
  try_to_find(type, method_name, params) or
  raise Pluginator::MissingPlugin.new(type, "first_ask: #{method_name}", plugins_map(type).keys)
end