Class: Aspera::Cli::PluginFactory
- Inherits:
-
Object
- Object
- Aspera::Cli::PluginFactory
- Includes:
- Singleton
- Defined in:
- lib/aspera/cli/plugin_factory.rb
Overview
Instantiate plugin from well-known locations
Instance Attribute Summary collapse
-
#lookup_folders ⇒ Object
readonly
Returns the value of attribute lookup_folders.
Instance Method Summary collapse
-
#add_lookup_folder(folder) ⇒ Object
add a folder to the list of folders to look for plugins.
-
#add_plugins_from_lookup_folders ⇒ Object
find plugins in defined paths.
-
#create(plugin_name_sym, **args) ⇒ Object
Create specified plugin.
-
#initialize ⇒ PluginFactory
constructor
A new instance of PluginFactory.
-
#plugin_class(plugin_name_sym) ⇒ Object
Class object for plugin.
-
#plugin_list ⇒ Object
List of registered plugins.
-
#plugin_source(plugin_name_sym) ⇒ Object
Path to source file of plugin.
Constructor Details
#initialize ⇒ PluginFactory
Returns a new instance of PluginFactory.
16 17 18 19 20 |
# File 'lib/aspera/cli/plugin_factory.rb', line 16 def initialize @lookup_folders = [] # information on plugins @plugins = {} end |
Instance Attribute Details
#lookup_folders ⇒ Object (readonly)
Returns the value of attribute lookup_folders.
14 15 16 |
# File 'lib/aspera/cli/plugin_factory.rb', line 14 def lookup_folders @lookup_folders end |
Instance Method Details
#add_lookup_folder(folder) ⇒ Object
add a folder to the list of folders to look for plugins
33 34 35 |
# File 'lib/aspera/cli/plugin_factory.rb', line 33 def add_lookup_folder(folder) @lookup_folders.unshift(folder) end |
#add_plugins_from_lookup_folders ⇒ Object
find plugins in defined paths
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aspera/cli/plugin_factory.rb', line 38 def add_plugins_from_lookup_folders @lookup_folders.each do |folder| next unless File.directory?(folder) # TODO: add gem root to load path ? and require short folder ? # $LOAD_PATH.push(folder) if i[:add_path] Dir.entries(folder).select{|file|file.end_with?(RUBY_FILE_EXT)}.each do |source| add_plugin_info(File.join(folder, source)) end end end |
#create(plugin_name_sym, **args) ⇒ Object
Create specified plugin
60 61 62 63 |
# File 'lib/aspera/cli/plugin_factory.rb', line 60 def create(plugin_name_sym, **args) # TODO: check that ancestor is Plugin? plugin_class(plugin_name_sym).new(**args) end |
#plugin_class(plugin_name_sym) ⇒ Object
Returns Class object for plugin.
50 51 52 53 54 55 |
# File 'lib/aspera/cli/plugin_factory.rb', line 50 def plugin_class(plugin_name_sym) raise "ERROR: plugin not found: #{plugin_name_sym}" unless @plugins.key?(plugin_name_sym) require @plugins[plugin_name_sym][:require_stanza] # Module.nesting[1] is Aspera::Cli return Object.const_get("#{Module.nesting[1]}::#{PLUGINS_MODULE}::#{plugin_name_sym.to_s.capitalize}") end |
#plugin_list ⇒ Object
Returns list of registered plugins.
23 24 25 |
# File 'lib/aspera/cli/plugin_factory.rb', line 23 def plugin_list @plugins.keys end |
#plugin_source(plugin_name_sym) ⇒ Object
Returns path to source file of plugin.
28 29 30 |
# File 'lib/aspera/cli/plugin_factory.rb', line 28 def plugin_source(plugin_name_sym) @plugins[plugin_name_sym][:source] end |