11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# 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) self.config.each do |name, val|
@all_names << name
next if val.nil?
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
@all_plugins.delete(parent)
next
end
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
@all_plugins.each { |p| p.settings.deep_merge!(val) if name == p.name }
end
@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
@plugins_to_run.each { |p| monitor << p }
@plugins_to_run = nil
end
|