class Nucleon::Plugin::Base

Public Class Methods

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

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
translate(data) click to toggle source
# 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

Public Instance Methods

admin_exec(return_result = true, &block) click to toggle source
# 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
alert(display, options = {}) click to toggle source
# File lib/core/plugin/base.rb, line 216
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 130
def code
  CORL.code
end
codes(*codes) click to toggle source
# File lib/core/plugin/base.rb, line 134
def codes(*codes)
  CORL.codes(*codes)
end
error(name, options = {}) click to toggle source
# 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
extended_config(type, options = {}) click to toggle source
# 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
extension(hook, options = {}, &code) click to toggle source
# 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
extension_check(hook, options = {}) click to toggle source
# 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
extension_collect(hook, options = {}) click to toggle source
# 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
extension_set(hook, value, options = {}) click to toggle source
# 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
hook_method(hook) click to toggle source
# File lib/core/plugin/base.rb, line 158
def hook_method(hook)
  "#{plugin_type}_#{plugin_provider}_#{hook}"  
end
info(name, options = {}) click to toggle source
# 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
me() click to toggle source
Alias for: myself
meta() click to toggle source
# File lib/core/plugin/base.rb, line 61
def meta
  return @meta
end
method_missing(method, *args, &block) click to toggle source
# File lib/core/plugin/base.rb, line 28
def method_missing(method, *args, &block)  
  return nil  
end
myself() click to toggle source
# File lib/core/plugin/base.rb, line 48
def myself
  Nucleon.handle(self)
end
Also aliased as: me
normalize(reload) click to toggle source
# File lib/core/plugin/base.rb, line 151
def normalize(reload)
  # Implement in sub classes
end
plugin_directory() click to toggle source
# File lib/core/plugin/base.rb, line 101
def plugin_directory
  return meta.get(:directory)
end
plugin_file() click to toggle source
# File lib/core/plugin/base.rb, line 107
def plugin_file
  return meta.get(:file)
end
plugin_instance_name() click to toggle source
# File lib/core/plugin/base.rb, line 113
def plugin_instance_name
  return meta.get(:instance_name)
end
plugin_name() click to toggle source
# File lib/core/plugin/base.rb, line 91
def plugin_name
  return meta.get(:name)
end
plugin_name=(plugin_name) click to toggle source
# File lib/core/plugin/base.rb, line 95
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 73
def plugin_namespace
  return meta.get(:namespace)
end
plugin_parent() click to toggle source
# File lib/core/plugin/base.rb, line 123
def plugin_parent
  return meta.get(:parent)
end
plugin_parent=(parent) click to toggle source
# File lib/core/plugin/base.rb, line 119
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 85
def plugin_provider
  return meta.get(:provider)
end
plugin_type() click to toggle source
# File lib/core/plugin/base.rb, line 79
def plugin_type
  return meta.get(:type)
end
quiet=(quiet) click to toggle source
# File lib/core/plugin/base.rb, line 55
def quiet=quiet
  @quiet = quiet
end
quiet?() click to toggle source
# File lib/core/plugin/base.rb, line 41
def quiet?
  @quiet
end
remove_plugin() click to toggle source
# File lib/core/plugin/base.rb, line 34
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 204
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 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
set_meta(meta) click to toggle source
# File lib/core/plugin/base.rb, line 67
def set_meta(meta)
  @meta = Config.ensure(meta)
end
status() click to toggle source
# File lib/core/plugin/base.rb, line 144
def status
  meta.get(:status, code.unknown_status)
end
status=(status) click to toggle source
# File lib/core/plugin/base.rb, line 140
def status=status
  meta.set(:status, status)
end
success(name, options = {}) click to toggle source
# 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
warn(name, options = {}) click to toggle source
# 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

Protected Instance Methods

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