class Nucleon::Plugin::Base

Public Class Methods

build_info(namespace, plugin_type, data) click to toggle source
# 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
init_plugin_collection(*external_block_methods) click to toggle source
# 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
new(namespace, plugin_type, provider, options) click to toggle source

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
register_ids() click to toggle source
# File lib/core/plugin/base.rb, line 6
def self.register_ids
  :name
end
translate(data) click to toggle source
# 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

Public Instance Methods

admin_exec(return_result = true, &block) click to toggle source
# 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
alert(display, options = {}) click to toggle source
# File lib/core/plugin/base.rb, line 226
def alert(display, options = {})
  ui.warn(display.strip, options) unless quiet? || display.strip.empty?
end
code() click to toggle source
# File lib/core/plugin/base.rb, line 140
def code
  Nucleon.code
end
codes(*codes) click to toggle source
# File lib/core/plugin/base.rb, line 144
def codes(*codes)
  Nucleon.codes(*codes)
end
error(name, options = {}) click to toggle source
# 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
extended_config(type, options = {}) click to toggle source
# 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
extension(hook, options = {}, &code) click to toggle source
# 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
extension_check(hook, options = {}) click to toggle source
# 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
extension_collect(hook, options = {}) click to toggle source
# 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
extension_set(hook, value, options = {}) click to toggle source
# 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
hook_method(hook) click to toggle source
# File lib/core/plugin/base.rb, line 168
def hook_method(hook)
  "#{plugin_type}_#{plugin_provider}_#{hook}"  
end
info(name, options = {}) click to toggle source
# 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
me() click to toggle source
Alias for: myself
meta() click to toggle source
# File lib/core/plugin/base.rb, line 71
def meta
  return @meta
end
method_missing(method, *args, &block) click to toggle source
# File lib/core/plugin/base.rb, line 38
def method_missing(method, *args, &block)  
  return nil  
end
myself() click to toggle source
# File lib/core/plugin/base.rb, line 58
def myself
  Nucleon.handle(self)
end
Also aliased as: me
normalize(reload) click to toggle source
# File lib/core/plugin/base.rb, line 161
def normalize(reload)
  # Implement in sub classes
end
parallel_finalize() click to toggle source
# File lib/core/plugin/base.rb, line 32
def parallel_finalize
  remove_plugin
end
plugin_directory() click to toggle source
# File lib/core/plugin/base.rb, line 111
def plugin_directory
  return meta.get(:directory)
end
plugin_file() click to toggle source
# File lib/core/plugin/base.rb, line 117
def plugin_file
  return meta.get(:file)
end
plugin_instance_name() click to toggle source
# File lib/core/plugin/base.rb, line 123
def plugin_instance_name
  return meta.get(:instance_name)
end
plugin_name() click to toggle source
# File lib/core/plugin/base.rb, line 101
def plugin_name
  return meta.get(:name)
end
plugin_name=(plugin_name) click to toggle source
# File lib/core/plugin/base.rb, line 105
def plugin_name=plugin_name
  meta.set(:name, string(plugin_name))
end
plugin_namespace() click to toggle source
# File lib/core/plugin/base.rb, line 83
def plugin_namespace
  return meta.get(:namespace)
end
plugin_parent() click to toggle source
# File lib/core/plugin/base.rb, line 133
def plugin_parent
  return meta.get(:parent)
end
plugin_parent=(parent) click to toggle source
# File lib/core/plugin/base.rb, line 129
def plugin_parent=parent
  meta.set(:parent, parent) if parent.is_a?(Nucleon::Plugin::Base)
end
plugin_provider() click to toggle source
# File lib/core/plugin/base.rb, line 95
def plugin_provider
  return meta.get(:provider)
end
plugin_type() click to toggle source
# File lib/core/plugin/base.rb, line 89
def plugin_type
  return meta.get(:type)
end
quiet=(quiet) click to toggle source
# File lib/core/plugin/base.rb, line 65
def quiet=quiet
  @quiet = quiet
end
quiet?() click to toggle source
# File lib/core/plugin/base.rb, line 51
def quiet?
  @quiet
end
remove_plugin() click to toggle source
# File lib/core/plugin/base.rb, line 44
def remove_plugin
  # Implement in sub classes if needed for cleanup
end
render(display, options = {}) click to toggle source
# File lib/core/plugin/base.rb, line 214
def render(display, options = {})
  ui.info(display.strip, options) unless quiet? || display.strip.empty?
end
safe_exec(return_result = true, &code) click to toggle source
# 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
set_meta(meta) click to toggle source
# File lib/core/plugin/base.rb, line 77
def set_meta(meta)
  @meta = Config.ensure(meta)
end
status() click to toggle source
# File lib/core/plugin/base.rb, line 154
def status
  meta.get(:status, code.unknown_status)
end
status=(status) click to toggle source
# File lib/core/plugin/base.rb, line 150
def status=status
  meta.set(:status, status)
end
success(name, options = {}) click to toggle source
# 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
warn(name, options = {}) click to toggle source
# 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

Protected Instance Methods

render_options() click to toggle source
# File lib/core/plugin/base.rb, line 207
def render_options
  export  
end