Class: PluginManager
- Inherits:
-
Object
- Object
- PluginManager
- Defined in:
- lib/seqtrimnext/classes/plugin_manager.rb
Instance Attribute Summary collapse
-
#plugin_names ⇒ Object
Returns the value of attribute plugin_names.
Instance Method Summary collapse
-
#check_plugins_params(params) ⇒ Object
Checks if the parameters are right for all plugins’s execution.
-
#execute_plugins(running_seqs) ⇒ Object
Receives the plugin’s list , and create an instance from its respective class (it’s that have the same name).
-
#initialize(plugin_list, params) ⇒ PluginManager
constructor
Storages the necessary plugins specified in ‘plugin_list’ and start the loading of plugins.
-
#load_plugins_from_files ⇒ Object
Iterates by the files from the folder ‘plugins’, and load it.
-
#load_plugins_from_files_old ⇒ Object
Iterates by the files from the folder ‘plugins’, and load it.
Constructor Details
#initialize(plugin_list, params) ⇒ PluginManager
Storages the necessary plugins specified in ‘plugin_list’ and start the loading of plugins
15 16 17 18 19 20 21 22 |
# File 'lib/seqtrimnext/classes/plugin_manager.rb', line 15 def initialize(plugin_list,params) @plugin_names = plugin_list.strip.split(',').map{|p| p.strip}.reject{|p| ['',nil].include?(p)} @params = params # puts plugin_list load_plugins_from_files end |
Instance Attribute Details
#plugin_names ⇒ Object
Returns the value of attribute plugin_names.
12 13 14 |
# File 'lib/seqtrimnext/classes/plugin_manager.rb', line 12 def plugin_names @plugin_names end |
Instance Method Details
#check_plugins_params(params) ⇒ Object
Checks if the parameters are right for all plugins’s execution. Finally return true if all is right or false if isn’t
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/seqtrimnext/classes/plugin_manager.rb', line 74 def check_plugins_params(params) res = true if !@plugin_names.empty? #$LOG.debug " Check params values #{plugin_list} " @plugin_names.each do |plugin_name| #Call to the respective plugin storaged in 'plugin_name' plugin_class = Object.const_get(plugin_name) # DONE - chequear si es un plugin de verdad u otra clase # puts plugin_class,plugin_class.ancestors.map {|e| puts e,e.class} if plugin_class.ancestors.include?(Plugin) errors=plugin_class.check_params(params) else errors= [plugin_name + ' is not a valid plugin'] end if !errors.empty? $LOG.error plugin_name+ ' found following errors:' errors.each do |error| $LOG.error ' -' + error res = false end #end each end #end if end #end each else $LOG.error "No plugin list provided" res = false end #end if plugin-list return res end |
#execute_plugins(running_seqs) ⇒ Object
Receives the plugin’s list , and create an instance from its respective class (it’s that have the same name)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/seqtrimnext/classes/plugin_manager.rb', line 25 def execute_plugins(running_seqs) # $LOG.info " Begin process: Execute plugins " if !@plugin_names.empty? # keeps a list of rejected sequences rejected_seqs = [] @plugin_names.each do |plugin_name| # remove rejected or empty seqs from execution list running_seqs.reverse_each do |seq| if seq.seq_rejected || seq.seq_fasta.empty? # remove from running running_seqs.delete(seq) # save in rejecteds rejected_seqs.push seq end end if running_seqs.empty? break end # Creates an instance of the respective plugin stored in "plugin_name",and asociate it to the sequence 'seq' plugin_class = Object.const_get(plugin_name) plugin_execution=plugin_class.new(running_seqs,@params) running_seqs.stats[plugin_name] = plugin_execution.stats # puts running_seqs.stats.to_json plugin_execution=nil end #end each running_seqs.add(rejected_seqs) else raise "Plugin list not found" end #end if lista-param end |
#load_plugins_from_files ⇒ Object
Iterates by the files from the folder ‘plugins’, and load it
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/seqtrimnext/classes/plugin_manager.rb', line 112 def load_plugins_from_files # DONE - CARGAR los plugins que hay en @plugin_names en vez de todos # the plugin_name changes to file using plugin_name.decamelize @plugin_names.each do |plugin_name| plugin_file = plugin_name.decamelize require plugin_file end end |
#load_plugins_from_files_old ⇒ Object
Iterates by the files from the folder ‘plugins’, and load it
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/seqtrimnext/classes/plugin_manager.rb', line 126 def load_plugins_from_files_old # DONE - CARGAR los plugins que hay en @plugin_names en vez de todos ignore = ['.','..','plugin.rb'] #carpeta=Dir.open("progs/ruby/seqtrimii/plugins") plugins_path = File.(File.join(File.dirname(__FILE__), "../plugins")) if !File.exists?(plugins_path) raise "Plugin folder does not exists" end # carpeta=Dir.open(plugins_path) entries = Dir.glob(File.join(plugins_path,'*.rb')) # carpeta. entries.each do |plugin| if !ignore.include?(plugin) require plugin end # end if end # end each end |