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
-
#first_ask(type, method_name, *params) ⇒ Object
Call a method on plugin and return first one that returns
true. -
#first_ask!(type, method_name, *params) ⇒ Object
Call a method on plugin and return first one that returns
true.
Methods included from PluginsMap
Instance Method Details
#first_ask(type, method_name, *params) ⇒ Object
Call a method on plugin and return first one that returns true.
15 16 17 18 19 20 21 |
# File 'lib/plugins/pluginator/extensions/first_ask.rb', line 15 def first_ask(type, method_name, *params) @plugins[type] or return nil @plugins[type].detect do |plugin| plugin.public_methods.map(&:to_sym).include?(method_name.to_sym) && plugin.send(method_name.to_sym, *params) end end |
#first_ask!(type, method_name, *params) ⇒ Object
Call a method on plugin and return first one that returns true. Behaves like first_ask but throws exceptions if can not find anything.
25 26 27 28 29 30 31 32 |
# File 'lib/plugins/pluginator/extensions/first_ask.rb', line 25 def first_ask!(type, method_name, *params) @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys) @plugins[type].detect do |plugin| plugin.public_methods.map(&:to_sym).include?(method_name.to_sym) && plugin.send(method_name, *params) end or raise Pluginator::MissingPlugin.new(type, "first_ask: #{method_name}", plugins_map(type).keys) end |