module Malevich::Loader
Public Instance Methods
find_plugin(name)
click to toggle source
# File lib/malevich/loader.rb, line 13 def find_plugin(name) @all_plugins.find { |p| p.name == name } end
load_plugins(plugin_path, config_file)
click to toggle source
# File lib/malevich/loader.rb, line 11 def load_plugins(plugin_path, config_file) def find_plugin(name) @all_plugins.find { |p| p.name == name } end @all_plugins = Malevich::DSL.load(plugin_path) @all_names = Array.new @plugins_to_run = Array.new self.config.deep_merge! YAML.load_file(config_file) #rescue {} self.config.each do |name, val| @all_names << name next if val.nil? # dup plugins for val - array if val.kind_of?(Array) parent = find_plugin(name) if parent.nil? Kernel::log :error, "Unable to find parent plugin for #{name}" next end val.each_with_index do |p_settings, i| child = parent.dup child.name = "#{name}_#{i}" child.settings.deep_merge!(parent.settings.dup) child.settings.deep_merge!(p_settings) @all_plugins << child @all_names << child.name end # delete parent plugin @all_plugins.delete(parent) next end # dup plugin with parent if val.is_a?(Hash) && val.has_key?('parent') parent_name = val['parent'] parent = find_plugin(parent_name) if parent.nil? Kernel::log :error, "Plugin #{parent_name} not found" next end child = parent.dup child.name = name child.settings.deep_merge!(parent.settings.dup) child.settings.deep_merge!(val) @all_plugins << child @all_names << child.name next end # over plugins merge @all_plugins.each { |p| p.settings.deep_merge!(val) if name == p.name } end # add plugin if it always_start or get settings and runnable @all_plugins.each do |p| unless p.always_start || @all_names.include?(p.name) Kernel::log(:info, "Plugin '#{p.name}' not started, because it not 'always_start' and not in config") next end @plugins_to_run << p if p.runnable? end @all_plugins = nil @all_names = nil # start plugins! @plugins_to_run.each { |p| monitor << p } @plugins_to_run = nil end
load_responders()
click to toggle source
# File lib/malevich/loader.rb, line 4 def load_responders Malevich::Responder.constants.select do |c| next unless Class === Malevich::Responder.const_get(c) monitor << Malevich::Responder.const_get(c).new end end