66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/cinchize.rb', line 66
def self.config options, network
config_file = options[:system] ? options[:system_config]: options[:local_config]
raise ArgumentError.new "the config file #{config_file} doesn't exist" unless File.exists? config_file
raise ArgumentError.new "needs a network" if network.nil? or network.empty?
cfg = JSON.parse File.open(config_file, "r").read()
raise ArgumentError.new "there's no server config in the config file" unless cfg.has_key? "servers"
raise ArgumentError.new "the config file doesn't contain a config for #{network}" unless cfg["servers"].has_key? network
ntw = cfg["servers"][network]
plugins = []
plugin_options = {}
ntw.delete("plugins").each do |plugin|
begin
raise LoadError.new "the module can't be null" if plugin["module"].nil?
raise NameError.new "the class can't be null" if plugin["class"].nil?
require plugin["module"]
clazz = nil
plugin["class"].split("::").inject(Object) { |m,n| clazz = m.const_get(n) }
plugins << clazz
plugin_options[clazz] = plugin["options"] || {}
rescue LoadError => e
puts "error while loading the module: #{e}"
rescue NameError => e
puts "error while loading the class: #{e}"
end
end
raise ArgumentError.new "no plugins loaded" if plugins.size == 0
cfg["options"] ||= {}
dir_mode = cfg["options"].key?("dir_mode") ? cfg["options"]["dir_mode"] : "normal"
daemon_options = {
:dir_mode => dir_mode.to_sym,
:dir => cfg["options"]["dir"] || Dir.getwd,
:log_output => cfg["options"]["log_output"] || false,
:app_name => "cinchize_#{network}",
:ontop => options[:ontop],
}
[daemon_options, ntw, plugins, plugin_options]
end
|