Class: Speedflow::PluginManager
- Inherits:
-
Object
- Object
- Speedflow::PluginManager
- Includes:
- ActiveSupport::Inflector, Message
- Defined in:
- lib/speedflow/plugin_manager.rb
Overview
Used to manage the plugins
Constant Summary collapse
- PLUGIN_BASE =
'speedflow-plugin-'.freeze
Instance Method Summary collapse
-
#call_action_from_step(step) ⇒ Object
Call action from flow step.
-
#call_plugin_action(plugin, action, arguments) ⇒ Object
Call plugin action.
-
#initialize(plugins = []) ⇒ PluginManager
constructor
Public: Constructor.
-
#load_plugins ⇒ Object
Public: Load plugins.
-
#require_plugin(plugin) ⇒ Object
Public: Require a plugins (from Gem).
Methods included from Message
#error, #info, #message, #notice, #success
Constructor Details
#initialize(plugins = []) ⇒ PluginManager
Public: Constructor
plugins - Array of plugins
Examples
PluginManager.new({})
# => <Speedflow::PluginManager>
Returns an Arrays of plugins.
19 20 21 22 |
# File 'lib/speedflow/plugin_manager.rb', line 19 def initialize(plugins = []) @plugins = plugins || [] load_plugins end |
Instance Method Details
#call_action_from_step(step) ⇒ Object
Call action from flow step.
step - Hash from flow. ”, action: ”, arguments: ”.
Returns nothing.
47 48 49 50 51 |
# File 'lib/speedflow/plugin_manager.rb', line 47 def call_action_from_step(step) step['arguments'] ||= {} success "Run action '#{step['action']}' of '#{step['plugin']}' plugin." call_plugin_action(step['plugin'], step['action'], step['arguments']) end |
#call_plugin_action(plugin, action, arguments) ⇒ Object
Call plugin action.
plugin - Plugin name. action - Action name. arguments - List of arguments
Returns nothing.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/speedflow/plugin_manager.rb', line 60 def call_plugin_action(plugin, action, arguments) action = underscore(action.prepend('action_')) module_name = plugin.downcase.capitalize.prepend('Speedflow::Plugin::') begin Kernel.const_get(module_name).send(action.to_s, arguments) rescue NoMethodError => exception = "Unable to call action: #{module_name}.#{action}\n" << exception. raise PluginActionNotFound, end end |
#load_plugins ⇒ Object
Public: Load plugins
Returns nothing.
27 28 29 |
# File 'lib/speedflow/plugin_manager.rb', line 27 def load_plugins @plugins.each { |plugin| require_plugin(plugin) } end |
#require_plugin(plugin) ⇒ Object
Public: Require a plugins (from Gem)
Returns nothing.
34 35 36 37 38 39 40 |
# File 'lib/speedflow/plugin_manager.rb', line 34 def require_plugin(plugin) require plugin.downcase.prepend(PLUGIN_BASE) rescue LoadError = "Unable to load plugin '#{plugin}'.\n" << "Help: `gem install #{PLUGIN_BASE}#{plugin}`" raise PluginNotFound, end |