Class: Vop::PluginLoader
- Inherits:
-
Object
- Object
- Vop::PluginLoader
- Defined in:
- lib/vop/parts/plugin_loader.rb
Instance Attribute Summary collapse
-
#loaded ⇒ Object
readonly
Returns the value of attribute loaded.
Instance Method Summary collapse
-
#initialize(op) ⇒ PluginLoader
constructor
A new instance of PluginLoader.
- #load(found, plugin_options = {}) ⇒ Object
- #new_plugin(plugin_name, plugin_path, plugin_options = {}) ⇒ Object
- #read_plugin(code, source_file = nil) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(op) ⇒ PluginLoader
Returns a new instance of PluginLoader.
11 12 13 14 15 |
# File 'lib/vop/parts/plugin_loader.rb', line 11 def initialize(op) @op = op extend PluginSyntax end |
Instance Attribute Details
#loaded ⇒ Object (readonly)
Returns the value of attribute loaded.
9 10 11 |
# File 'lib/vop/parts/plugin_loader.rb', line 9 def loaded @loaded end |
Instance Method Details
#load(found, plugin_options = {}) ⇒ Object
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 |
# File 'lib/vop/parts/plugin_loader.rb', line 35 def load(found, = {}) reset (plugins, templates) = [found.plugins, found.templates] plugins.each do |plugin_path| name = File.basename(plugin_path) $logger.debug "loading #{name} from #{plugin_path}" plugin = new_plugin(name, plugin_path, ) templates.each do |template| template_path = File.dirname(template) if plugin_path.start_with? template_path $logger.debug " (applying template #{template_path})" template_file = File.join(template_path, "plugin.vop") code = File.read(template_file) read_plugin(code, template_file) end end plugin_file = File.join(plugin_path, "#{name}.plugin") next unless File.exists?(plugin_file) $logger.debug "reading plugin '#{name}' from '#{plugin_file}'" code = File.read(plugin_file) read_plugin(code, plugin_file) @loaded << @plugin $logger.debug "loaded plugin #{@plugin.name}" end self end |
#new_plugin(plugin_name, plugin_path, plugin_options = {}) ⇒ Object
21 22 23 24 |
# File 'lib/vop/parts/plugin_loader.rb', line 21 def new_plugin(plugin_name, plugin_path, = {}) @plugin = Plugin.new(@op, plugin_name, plugin_path, ) @plugin end |
#read_plugin(code, source_file = nil) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/vop/parts/plugin_loader.rb', line 26 def read_plugin(code, source_file = nil) begin instance_eval(code, source_file) rescue => detail $logger.warn "problem loading plugin #{@plugin.name} : #{detail.}\n#{detail.backtrace.join("\n")}" raise Errors::PluginLoadError.new(detail) end end |
#reset ⇒ Object
17 18 19 |
# File 'lib/vop/parts/plugin_loader.rb', line 17 def reset @loaded = [] end |