Class: Aspera::Cli::PluginFactory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/aspera/cli/plugin_factory.rb

Overview

option is retrieved from another object using accessor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePluginFactory

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_foldersObject (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



30
31
32
# File 'lib/aspera/cli/plugin_factory.rb', line 30

def add_lookup_folder(folder)
  @lookup_folders.unshift(folder)
end

#add_plugins_from_lookup_foldersObject

find plugins in defined paths



35
36
37
38
39
40
41
42
43
44
# File 'lib/aspera/cli/plugin_factory.rb', line 35

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



53
54
55
56
# File 'lib/aspera/cli/plugin_factory.rb', line 53

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



46
47
48
49
50
51
# File 'lib/aspera/cli/plugin_factory.rb', line 46

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_listObject



22
23
24
# File 'lib/aspera/cli/plugin_factory.rb', line 22

def plugin_list
  @plugins.keys
end

#plugin_source(plugin_name_sym) ⇒ Object



26
27
28
# File 'lib/aspera/cli/plugin_factory.rb', line 26

def plugin_source(plugin_name_sym)
  @plugins[plugin_name_sym][:source]
end