# File lib/core/plugin/base.rb, line 241 def self.build_info(type, data) plugins = [] if data.is_a?(Hash) data = [ data ] end logger.debug("Building plugin list of #{type} from data: #{data.inspect}") if data.is_a?(Array) data.each do |info| unless Util::Data.empty?(info) info = translate(info) if Util::Data.empty?(info[:provider]) info[:provider] = Nucleon.type_default(type) end logger.debug("Translated plugin info: #{info.inspect}") plugins << info end end end return plugins end
# File lib/core/plugin/base.rb, line 277 def self.init_plugin_collection(*external_block_methods) logger.debug("Initializing plugin collection interface at #{Time.now}") include Parallel external_block_exec(*external_block_methods) include Mixin::Settings include Mixin::SubConfig extend Mixin::Macro::PluginInterface end
All Plugin classes should directly or indirectly extend Base
# File lib/core/plugin/base.rb, line 8 def initialize(type, provider, options) config = Util::Data.clean(Config.ensure(options), false) name = Util::Data.ensure_value(config.delete(:plugin_name), config.delete(:name, provider)) @quiet = config.delete(:quiet, false) set_meta(config.delete(:meta, Config.new)) # No logging statements aove this line!! super(config.import({ :logger => "#{plugin_type}->#{plugin_provider}" }), {}, true, false) myself.plugin_name = name logger.debug("Normalizing #{plugin_type} plugin #{plugin_name} with meta data: #{meta.inspect}") normalize(false) @initialized = true end
# File lib/core/plugin/base.rb, line 270 def self.translate(data) logger.debug("Translating data to internal plugin structure: #{data.inspect}") return ( data.is_a?(Hash) ? symbol_map(data) : data ) end
# File lib/core/plugin/base.rb, line 308 def admin_exec(return_result = true, &block) if Nucleon.admin? safe_exec(return_result, &block) else ui.warn("The #{plugin_provider} action must be run as a machine administrator") myself.status = code.access_denied end end
# File lib/core/plugin/base.rb, line 216 def alert(display, options = {}) ui.warn(display.strip, options) unless quiet? || display.strip.empty? end
# File lib/core/plugin/base.rb, line 130 def code CORL.code end
# File lib/core/plugin/base.rb, line 134 def codes(*codes) CORL.codes(*codes) end
# File lib/core/plugin/base.rb, line 228 def error(name, options = {}) ui.error(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet? end
# File lib/core/plugin/base.rb, line 170 def extended_config(type, options = {}) config = Nucleon.config(type, Config.ensure(options).import({ :plugin => myself })) config.delete(:plugin) config end
# File lib/core/plugin/base.rb, line 164 def extension(hook, options = {}, &code) Nucleon.exec(hook_method(hook), Config.ensure(options).import({ :plugin => myself }), &code) end
# File lib/core/plugin/base.rb, line 178 def extension_check(hook, options = {}) Nucleon.check(hook_method(hook), Config.ensure(options).import({ :plugin => myself })) end
# File lib/core/plugin/base.rb, line 190 def extension_collect(hook, options = {}) Nucleon.collect(hook_method(hook), Config.ensure(options).import({ :plugin => myself })) end
# File lib/core/plugin/base.rb, line 184 def extension_set(hook, value, options = {}) Nucleon.value(hook_method(hook), value, Config.ensure(options).import({ :plugin => myself })) end
# File lib/core/plugin/base.rb, line 158 def hook_method(hook) "#{plugin_type}_#{plugin_provider}_#{hook}" end
# File lib/core/plugin/base.rb, line 210 def info(name, options = {}) ui.info(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet? end
# File lib/core/plugin/base.rb, line 61 def meta return @meta end
# File lib/core/plugin/base.rb, line 28 def method_missing(method, *args, &block) return nil end
# File lib/core/plugin/base.rb, line 48 def myself Nucleon.handle(self) end
# File lib/core/plugin/base.rb, line 151 def normalize(reload) # Implement in sub classes end
# File lib/core/plugin/base.rb, line 101 def plugin_directory return meta.get(:directory) end
# File lib/core/plugin/base.rb, line 107 def plugin_file return meta.get(:file) end
# File lib/core/plugin/base.rb, line 113 def plugin_instance_name return meta.get(:instance_name) end
# File lib/core/plugin/base.rb, line 91 def plugin_name return meta.get(:name) end
# File lib/core/plugin/base.rb, line 95 def plugin_name=plugin_name meta.set(:name, string(plugin_name)) end
# File lib/core/plugin/base.rb, line 73 def plugin_namespace return meta.get(:namespace) end
# File lib/core/plugin/base.rb, line 123 def plugin_parent return meta.get(:parent) end
# File lib/core/plugin/base.rb, line 119 def plugin_parent=parent meta.set(:parent, parent) if parent.is_a?(Nucleon::Plugin::Base) end
# File lib/core/plugin/base.rb, line 85 def plugin_provider return meta.get(:provider) end
# File lib/core/plugin/base.rb, line 79 def plugin_type return meta.get(:type) end
# File lib/core/plugin/base.rb, line 55 def quiet=quiet @quiet = quiet end
# File lib/core/plugin/base.rb, line 41 def quiet? @quiet end
# File lib/core/plugin/base.rb, line 34 def remove_plugin # Implement in sub classes if needed for cleanup end
# File lib/core/plugin/base.rb, line 204 def render(display, options = {}) ui.info(display.strip, options) unless quiet? || display.strip.empty? end
# File lib/core/plugin/base.rb, line 291 def safe_exec(return_result = true, &code) begin result = code.call return result if return_result return true rescue Exception => error logger.error(error.inspect) logger.error(error.message) ui.error(error.message, { :prefix => false }) if error.message end return false end
# File lib/core/plugin/base.rb, line 67 def set_meta(meta) @meta = Config.ensure(meta) end
# File lib/core/plugin/base.rb, line 144 def status meta.get(:status, code.unknown_status) end
# File lib/core/plugin/base.rb, line 140 def status=status meta.set(:status, status) end
# File lib/core/plugin/base.rb, line 234 def success(name, options = {}) ui.success(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet? end
# File lib/core/plugin/base.rb, line 222 def warn(name, options = {}) ui.warn(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet? end
# File lib/core/plugin/base.rb, line 197 def render_options export end