# File lib/core/plugin/base.rb, line 251 def self.build_info(namespace, plugin_type, data) plugins = [] if data.is_a?(Hash) data = [ data ] end logger.debug("Building plugin list of #{plugin_type}") 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(namespace, plugin_type) end plugins << info end end end return plugins end
# File lib/core/plugin/base.rb, line 285 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 12 def initialize(namespace, plugin_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 above this line!! super(config.import({ :logger => "#{namespace}->#{plugin_type}->#{plugin_provider}" }), {}, true, false) myself.plugin_name = name logger.debug("Normalizing #{namespace} #{plugin_type} plugin #{plugin_name}") normalize(false) @initialized = true end
# File lib/core/plugin/base.rb, line 6 def self.register_ids :name end
# File lib/core/plugin/base.rb, line 278 def self.translate(data) logger.debug("Translating input data to internal plugin structure") return ( data.is_a?(Hash) ? symbol_map(data) : data ) end
# File lib/core/plugin/base.rb, line 316 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 226 def alert(display, options = {}) ui.warn(display.strip, options) unless quiet? || display.strip.empty? end
# File lib/core/plugin/base.rb, line 140 def code Nucleon.code end
# File lib/core/plugin/base.rb, line 144 def codes(*codes) Nucleon.codes(*codes) end
# File lib/core/plugin/base.rb, line 238 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 180 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 174 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 188 def extension_check(hook, options = {}) Nucleon.check(hook_method(hook), Config.ensure(options).import({ :plugin => myself })) end
# File lib/core/plugin/base.rb, line 200 def extension_collect(hook, options = {}) Nucleon.collect(hook_method(hook), Config.ensure(options).import({ :plugin => myself })) end
# File lib/core/plugin/base.rb, line 194 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 168 def hook_method(hook) "#{plugin_type}_#{plugin_provider}_#{hook}" end
# File lib/core/plugin/base.rb, line 220 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 71 def meta return @meta end
# File lib/core/plugin/base.rb, line 38 def method_missing(method, *args, &block) return nil end
# File lib/core/plugin/base.rb, line 58 def myself Nucleon.handle(self) end
# File lib/core/plugin/base.rb, line 161 def normalize(reload) # Implement in sub classes end
# File lib/core/plugin/base.rb, line 32 def parallel_finalize remove_plugin end
# File lib/core/plugin/base.rb, line 111 def plugin_directory return meta.get(:directory) end
# File lib/core/plugin/base.rb, line 117 def plugin_file return meta.get(:file) end
# File lib/core/plugin/base.rb, line 123 def plugin_instance_name return meta.get(:instance_name) end
# File lib/core/plugin/base.rb, line 101 def plugin_name return meta.get(:name) end
# File lib/core/plugin/base.rb, line 105 def plugin_name=plugin_name meta.set(:name, string(plugin_name)) end
# File lib/core/plugin/base.rb, line 83 def plugin_namespace return meta.get(:namespace) end
# File lib/core/plugin/base.rb, line 133 def plugin_parent return meta.get(:parent) end
# File lib/core/plugin/base.rb, line 129 def plugin_parent=parent meta.set(:parent, parent) if parent.is_a?(Nucleon::Plugin::Base) end
# File lib/core/plugin/base.rb, line 95 def plugin_provider return meta.get(:provider) end
# File lib/core/plugin/base.rb, line 89 def plugin_type return meta.get(:type) end
# File lib/core/plugin/base.rb, line 65 def quiet=quiet @quiet = quiet end
# File lib/core/plugin/base.rb, line 51 def quiet? @quiet end
# File lib/core/plugin/base.rb, line 44 def remove_plugin # Implement in sub classes if needed for cleanup end
# File lib/core/plugin/base.rb, line 214 def render(display, options = {}) ui.info(display.strip, options) unless quiet? || display.strip.empty? end
# File lib/core/plugin/base.rb, line 299 def safe_exec(return_result = true, &code) begin result = code.call return result if return_result return true rescue => 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 77 def set_meta(meta) @meta = Config.ensure(meta) end
# File lib/core/plugin/base.rb, line 154 def status meta.get(:status, code.unknown_status) end
# File lib/core/plugin/base.rb, line 150 def status=status meta.set(:status, status) end
# File lib/core/plugin/base.rb, line 244 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 232 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 207 def render_options export end