class SimplyGenius::Atmos::PluginManager

Attributes

plugins[R]

Public Class Methods

new(plugins) click to toggle source
# File lib/simplygenius/atmos/plugin_manager.rb, line 13
def initialize(plugins)
  @plugins = []
  Array(plugins).each do |plugin|
    if plugin.is_a?(String)
      name = plugin
      plugin = SettingsHash.new
      plugin[:name] = name
    elsif plugin.is_a?(Hash)
      plugin = SettingsHash.new(plugin)
      if plugin[:name].blank?
        logger.error "Invalid plugin definition, :name missing: #{plugin}"
        next
      end
    else
      logger.error "Invalid plugin definition: #{plugin}"
      next
    end
    @plugins << plugin
  end

  @plugin_classes = Set.new
  @plugin_instances = []
  @output_filters = {}
end

Public Instance Methods

load_plugin(plugin) click to toggle source
# File lib/simplygenius/atmos/plugin_manager.rb, line 57
def load_plugin(plugin)
  begin
    name = plugin[:name]
    require_name = plugin[:require] || name.gsub('-', '/')
    logger.debug("Loading plugin #{name} as #{require_name}")
    require require_name
  rescue LoadError, StandardError => e
    logger.log_exception e, "Failed to load atmos plugin: #{name} - #{e.message}"
  end
end
load_plugins() click to toggle source
# File lib/simplygenius/atmos/plugin_manager.rb, line 38
def load_plugins
  @plugins.each do |plugin|
    load_plugin(plugin)

    # Check for new plugin classes after each plugin load so that we can
    # initialize them with their own config hash
    Plugin.descendants.each do |plugin_class|
      begin
        if ! @plugin_classes.include?(plugin_class)
          @plugin_classes << plugin_class
          @plugin_instances << plugin_class.new(self, plugin)
        end
      rescue StandardError => e
        logger.log_exception e, "Failed to initialize plugin: #{plugin_class}"
      end
    end
  end
end
output_filters(type, context) click to toggle source
# File lib/simplygenius/atmos/plugin_manager.rb, line 78
def output_filters(type, context)
  validate_output_filter_type(type)
  @output_filters[type.to_sym] ||= []
  return OutputFilterCollection.new(@output_filters[type.to_sym].collect {|clazz| clazz.new(context) })
end
register_output_filter(type, clazz) click to toggle source
# File lib/simplygenius/atmos/plugin_manager.rb, line 72
def register_output_filter(type, clazz)
  validate_output_filter_type(type)
  @output_filters[type.to_sym] ||= []
  @output_filters[type.to_sym] << clazz
end
validate_output_filter_type(type) click to toggle source
# File lib/simplygenius/atmos/plugin_manager.rb, line 68
def validate_output_filter_type(type)
  raise "Invalid output filter type #{type}, must be one of [:stdout, :stderr]" unless [:stdout, :stderr].include?(type)
end