Class: Nucleon::Plugin::Base
- Defined in:
- lib/core/plugin/base.rb
Instance Attribute Summary
Attributes inherited from Core
Class Method Summary collapse
-
.build_info(namespace, plugin_type, data) ⇒ Object
—————————————————————————– Utilities.
-
.code ⇒ Object
—————————————————————————– Status codes.
- .codes(*codes) ⇒ Object
-
.init_plugin_collection(*external_block_methods) ⇒ Object
—.
- .register_ids ⇒ Object
-
.translate(data) ⇒ Object
—.
-
.translate_reference(reference, editable = false) ⇒ Object
—.
Instance Method Summary collapse
-
#admin_exec(return_result = true, &block) ⇒ Object
—.
-
#ask(message, options = {}) ⇒ Object
—————————————————————————– Input.
- #code ⇒ Object
- #codes(*codes) ⇒ Object
-
#error(message, options = {}) ⇒ Object
—.
-
#extended_config(type, options = {}) ⇒ Object
—.
-
#extension(hook, options = {}, &code) ⇒ Object
—.
-
#extension_check(hook, options = {}) ⇒ Object
—.
-
#extension_collect(hook, options = {}) ⇒ Object
—.
-
#extension_set(hook, value, options = {}) ⇒ Object
—.
-
#hook_method(hook) ⇒ Object
—————————————————————————– Extensions.
-
#info(message, options = {}) ⇒ Object
—.
-
#initialize(namespace, plugin_type, provider, options) ⇒ Base
constructor
All Plugin classes should directly or indirectly extend Base.
-
#meta ⇒ Object
—.
-
#method_missing(method, *args, &block) ⇒ Object
—.
-
#myself ⇒ Object
(also: #me)
—————————————————————————– Property accessor / modifiers.
-
#normalize(reload) ⇒ Object
—————————————————————————– Plugin operations.
-
#parallel_finalize ⇒ Object
—.
-
#password(type, options = {}) ⇒ Object
—.
-
#plugin_directory ⇒ Object
—.
-
#plugin_file ⇒ Object
—.
-
#plugin_instance_name ⇒ Object
—.
-
#plugin_name ⇒ Object
—.
- #plugin_name=(plugin_name) ⇒ Object
-
#plugin_namespace ⇒ Object
—.
- #plugin_parent ⇒ Object
-
#plugin_parent=(parent) ⇒ Object
—.
-
#plugin_provider ⇒ Object
—.
-
#plugin_type ⇒ Object
—.
-
#prefixed_message(type, prefix, message, options = {}) ⇒ Object
—.
-
#quiet=(quiet) ⇒ Object
—.
-
#quiet? ⇒ Boolean
—————————————————————————– Checks.
-
#remove_plugin ⇒ Object
—.
-
#render(data, options = {}) ⇒ Object
—.
-
#safe_exec(return_result = true, &code) ⇒ Object
—.
-
#set_meta(meta) ⇒ Object
—.
- #status ⇒ Object
-
#status=(status) ⇒ Object
—.
-
#success(message, options = {}) ⇒ Object
—.
-
#translate_reference(reference, editable = false) ⇒ Object
—.
-
#warn(message, options = {}) ⇒ Object
—.
Methods inherited from Core
#initialized?, logger, ui, ui_group, #ui_group
Methods included from Mixin::Colors
#black, #blue, #cyan, #green, #grey, #purple, #red, #yellow
Methods inherited from Config
#[], #[]=, #append, array, #array, #clear, #defaults, #delete, #empty?, ensure, #export, #filter, filter, #get, #get_array, #get_hash, #has_key?, hash, #hash, #import, #init, init, init_flat, #keys, #prepend, #set, #string, string, string_map, #string_map, symbol, #symbol, #symbol_array, #symbol_map, symbol_map, test, #test
Methods included from Mixin::ConfigOptions
#all_options, #clear_options, #contexts, #get_options, #set_options
Methods included from Mixin::ConfigCollection
#all_properties, #clear_properties, #delete_property, #get_property, #save_properties, #set_property
Constructor Details
#initialize(namespace, plugin_type, provider, options) ⇒ Base
All Plugin classes should directly or indirectly extend Base
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/core/plugin/base.rb', line 12 def initialize(namespace, plugin_type, provider, ) @actor = Nucleon.handle(self) config = Util::Data.clean(Config.ensure(), false) name = Util::Data.ensure_value(config.delete(:plugin_name), config.delete(:name, provider)) @quiet = config.delete(:quiet, false) (config.delete(:meta, Config.new)) # No logging statements above this line!! super(config.import({ :logger => "#{namespace}->#{plugin_type}->#{plugin_provider}" }), {}, true, false, false) myself.plugin_name = name logger.debug("Normalizing #{namespace} #{plugin_type} plugin #{plugin_name}") normalize(false) @initialized = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
40 41 42 |
# File 'lib/core/plugin/base.rb', line 40 def method_missing(method, *args, &block) return nil end |
Class Method Details
.build_info(namespace, plugin_type, data) ⇒ Object
Utilities
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/core/plugin/base.rb', line 346 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 |
.code ⇒ Object
Status codes
142 143 144 |
# File 'lib/core/plugin/base.rb', line 142 def self.code Nucleon.code end |
.codes(*codes) ⇒ Object
150 151 152 |
# File 'lib/core/plugin/base.rb', line 150 def self.codes(*codes) Nucleon.codes(*codes) end |
.init_plugin_collection(*external_block_methods) ⇒ Object
407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/core/plugin/base.rb', line 407 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 |
.register_ids ⇒ Object
6 7 8 |
# File 'lib/core/plugin/base.rb', line 6 def self.register_ids [ :plugin_name, :name ] end |
.translate(data) ⇒ Object
373 374 375 376 |
# File 'lib/core/plugin/base.rb', line 373 def self.translate(data) logger.debug("Translating input data to internal plugin structure") return ( data.is_a?(Hash) ? symbol_map(data) : data ) end |
.translate_reference(reference, editable = false) ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/core/plugin/base.rb', line 380 def self.translate_reference(reference, editable = false) # ex: provider:::name if reference && reference.match(/^\s*([a-zA-Z0-9_-]+)(?::::)?(.*)?\s*$/) provider = $1 name = $2 logger.debug("Translating plugin reference: #{provider} #{name}") info = { :provider => provider, :name => name } logger.debug("Plugin reference info: #{info.inspect}") return info end nil end |
Instance Method Details
#admin_exec(return_result = true, &block) ⇒ Object
438 439 440 441 442 443 444 445 |
# File 'lib/core/plugin/base.rb', line 438 def admin_exec(return_result = true, &block) if Nucleon.admin? safe_exec(return_result, &block) else warn("The #{plugin_provider} action must be run as a machine administrator", { :i18n => false }) myself.status = code.access_denied end end |
#ask(message, options = {}) ⇒ Object
Input
217 218 219 |
# File 'lib/core/plugin/base.rb', line 217 def ask(, = {}) ui.ask(, ) end |
#code ⇒ Object
146 147 148 |
# File 'lib/core/plugin/base.rb', line 146 def code self.class.code end |
#codes(*codes) ⇒ Object
154 155 156 |
# File 'lib/core/plugin/base.rb', line 154 def codes(*codes) self.class.codes(*codes) end |
#error(message, options = {}) ⇒ Object
314 315 316 317 318 319 320 321 322 |
# File 'lib/core/plugin/base.rb', line 314 def error(, = {}) config = Config.new().import({ :operation => :error }) unless quiet? = (, config) ui.error(, config.export) end end |
#extended_config(type, options = {}) ⇒ Object
190 191 192 193 194 |
# File 'lib/core/plugin/base.rb', line 190 def extended_config(type, = {}) config = Nucleon.config(type, Config.ensure().import({ :plugin => myself })) config.delete(:plugin) config end |
#extension(hook, options = {}, &code) ⇒ Object
184 185 186 |
# File 'lib/core/plugin/base.rb', line 184 def extension(hook, = {}, &code) Nucleon.exec(hook_method(hook), Config.ensure().import({ :plugin => myself }), &code) end |
#extension_check(hook, options = {}) ⇒ Object
198 199 200 |
# File 'lib/core/plugin/base.rb', line 198 def extension_check(hook, = {}) Nucleon.check(hook_method(hook), Config.ensure().import({ :plugin => myself })) end |
#extension_collect(hook, options = {}) ⇒ Object
210 211 212 |
# File 'lib/core/plugin/base.rb', line 210 def extension_collect(hook, = {}) Nucleon.collect(hook_method(hook), Config.ensure().import({ :plugin => myself })) end |
#extension_set(hook, value, options = {}) ⇒ Object
204 205 206 |
# File 'lib/core/plugin/base.rb', line 204 def extension_set(hook, value, = {}) Nucleon.value(hook_method(hook), value, Config.ensure().import({ :plugin => myself })) end |
#hook_method(hook) ⇒ Object
Extensions
178 179 180 |
# File 'lib/core/plugin/base.rb', line 178 def hook_method(hook) "#{plugin_type}_#{plugin_provider}_#{hook}" end |
#info(message, options = {}) ⇒ Object
290 291 292 293 294 295 296 297 298 |
# File 'lib/core/plugin/base.rb', line 290 def info(, = {}) config = Config.new().import({ :operation => :info }) unless quiet? = (, config) ui.info(, config.export) end end |
#meta ⇒ Object
73 74 75 |
# File 'lib/core/plugin/base.rb', line 73 def return @meta end |
#myself ⇒ Object Also known as: me
Property accessor / modifiers
60 61 62 |
# File 'lib/core/plugin/base.rb', line 60 def myself @actor end |
#normalize(reload) ⇒ Object
Plugin operations
171 172 173 |
# File 'lib/core/plugin/base.rb', line 171 def normalize(reload) # Implement in sub classes end |
#parallel_finalize ⇒ Object
34 35 36 |
# File 'lib/core/plugin/base.rb', line 34 def parallel_finalize remove_plugin end |
#password(type, options = {}) ⇒ Object
223 224 225 |
# File 'lib/core/plugin/base.rb', line 223 def password(type, = {}) ui.password(type, ) end |
#plugin_directory ⇒ Object
113 114 115 |
# File 'lib/core/plugin/base.rb', line 113 def plugin_directory return .get(:directory) end |
#plugin_file ⇒ Object
119 120 121 |
# File 'lib/core/plugin/base.rb', line 119 def plugin_file return .get(:file) end |
#plugin_instance_name ⇒ Object
125 126 127 |
# File 'lib/core/plugin/base.rb', line 125 def plugin_instance_name return .get(:instance_name) end |
#plugin_name ⇒ Object
103 104 105 |
# File 'lib/core/plugin/base.rb', line 103 def plugin_name return .get(:name) end |
#plugin_name=(plugin_name) ⇒ Object
107 108 109 |
# File 'lib/core/plugin/base.rb', line 107 def plugin_name=plugin_name .set(:name, string(plugin_name)) end |
#plugin_namespace ⇒ Object
85 86 87 |
# File 'lib/core/plugin/base.rb', line 85 def plugin_namespace return .get(:namespace) end |
#plugin_parent ⇒ Object
135 136 137 |
# File 'lib/core/plugin/base.rb', line 135 def plugin_parent return .get(:parent) end |
#plugin_parent=(parent) ⇒ Object
131 132 133 |
# File 'lib/core/plugin/base.rb', line 131 def plugin_parent=parent .set(:parent, parent) if parent.is_a?(Nucleon::Plugin::Base) end |
#plugin_provider ⇒ Object
97 98 99 |
# File 'lib/core/plugin/base.rb', line 97 def plugin_provider return .get(:provider) end |
#plugin_type ⇒ Object
91 92 93 |
# File 'lib/core/plugin/base.rb', line 91 def plugin_type return .get(:type) end |
#prefixed_message(type, prefix, message, options = {}) ⇒ Object
338 339 340 341 |
# File 'lib/core/plugin/base.rb', line 338 def (type, prefix, , = {}) return unless [ :info, :warn, :error, :success ].include?(type.to_sym) send(type, prefix.to_s + (, Config.new().import({ :prefix => false, :operation => type.to_sym }).export), Config.new().import({ :i18n => false }).export) end |
#quiet=(quiet) ⇒ Object
67 68 69 |
# File 'lib/core/plugin/base.rb', line 67 def quiet=quiet @quiet = quiet end |
#quiet? ⇒ Boolean
Checks
53 54 55 |
# File 'lib/core/plugin/base.rb', line 53 def quiet? @quiet end |
#remove_plugin ⇒ Object
46 47 48 |
# File 'lib/core/plugin/base.rb', line 46 def remove_plugin # Implement in sub classes if needed for cleanup end |
#render(data, options = {}) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/core/plugin/base.rb', line 275 def render(data, = {}) config = Config.ensure() if ! quiet? || config[:silent] translator = nil translator = Nucleon.translator({}, config[:format]) if config[:format] data = translator.generate(data) if translator ui.dump(data, ) unless data.strip.empty? || config[:silent] end data end |
#safe_exec(return_result = true, &code) ⇒ Object
421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/core/plugin/base.rb', line 421 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.) error(error., { :prefix => false, :i18n => false }) if error. end return false end |
#set_meta(meta) ⇒ Object
79 80 81 |
# File 'lib/core/plugin/base.rb', line 79 def () @meta = Config.ensure() end |
#status ⇒ Object
164 165 166 |
# File 'lib/core/plugin/base.rb', line 164 def status .get(:status, code.unknown_status) end |
#status=(status) ⇒ Object
160 161 162 |
# File 'lib/core/plugin/base.rb', line 160 def status=status .set(:status, status) end |
#success(message, options = {}) ⇒ Object
326 327 328 329 330 331 332 333 334 |
# File 'lib/core/plugin/base.rb', line 326 def success(, = {}) config = Config.new().import({ :operation => :success }) unless quiet? = (, config) ui.success(, config.export) end end |
#translate_reference(reference, editable = false) ⇒ Object
401 402 403 |
# File 'lib/core/plugin/base.rb', line 401 def translate_reference(reference, editable = false) myself.class.translate_reference(reference, editable) end |