class Speedflow::Plugin::Manager
Used to manage the plugins
Constants
- PLUGIN_BASE
Attributes
@return [Speedflow::Plugin::Configuration] Plugin
configuration object.
@return [Speedflow::Plugin::Prompt] Plugin
prompt object.
Public Class Methods
Public: Constructor
plugins - Array of plugins
Examples
Manager.new([]) # => <Speedflow::Plugin::Manager>
Returns an Arrays of plugins.
# File lib/speedflow/plugin/manager.rb, line 28 def initialize(plugins = []) @plugins = plugins || [] load_plugins end
Public Instance Methods
Call action.
plugin_name - Plugin
name. action_name - Action name. arguments - List of arguments.
Returns Hash
of action output.
# File lib/speedflow/plugin/manager.rb, line 79 def action(plugin, action_name) plugin_name = plugin.class.name.split('::')[-2].downcase action_name = action_name.prepend('action_').underscore unless plugin.respond_to?(action_name) message = "Unable to call action: #{plugin_name}.#{action_name}" raise PluginActionNotFound, message end # TODO: Remove underground prompt. success "Run action '#{action_name}' of '#{plugin_name}' plugin." plugin.send action_name end
Call action from flow step.
step - Hash
from flow. {plugin: '', action: '', arguments: ''}.
Returns nothing.
# File lib/speedflow/plugin/manager.rb, line 56 def action_from_step(step) plugin = plugin(step['plugin'], step['arguments']) action(plugin, step['action']) end
Public: Plugin
configuration object.
Returns Speedflow::Plugin::Configuration
.
# File lib/speedflow/plugin/manager.rb, line 110 def config @config ||= Configuration end
Public: Load plugins
Returns nothing.
# File lib/speedflow/plugin/manager.rb, line 36 def load_plugins @plugins.each { |plugin| require_plugin(plugin) } end
Call plugin.
plugin_name - Plugin
name. arguments - List of arguments.
Returns <Speedflow::Plugin::Abstract>.
# File lib/speedflow/plugin/manager.rb, line 67 def plugin(plugin_name, arguments) configuration = config.new(arguments, plugin_name) plugin_object(plugin_name).new(configuration, prompt.new) end
Public: Get plugin object from plugin name
plugin_name - Plugin
name.
TODO: Create Utils::name_to_object method.
Returns Object.
# File lib/speedflow/plugin/manager.rb, line 101 def plugin_object(plugin_name) plugin_name = plugin_name.downcase.capitalize "Speedflow::Plugin::#{plugin_name}::Plugin".constantize end
Public: Plugin
prompt object.
Returns Speedflow::Plugin::Prompt
.
# File lib/speedflow/plugin/manager.rb, line 117 def prompt @prompt ||= ::TTY::Prompt end
Public: Require a plugins (from Gem)
Returns nothing.
# File lib/speedflow/plugin/manager.rb, line 43 def require_plugin(plugin) require plugin.downcase.prepend(PLUGIN_BASE) rescue LoadError message = "Unable to load plugin '#{plugin}'.\n" message << "Help: `gem install #{PLUGIN_BASE}#{plugin}`" raise PluginNotFound, message end