Revision ecdabe95
Added by Marc Dequènes almost 14 years ago
- ID ecdabe959057281f9350bbcd0735c9639206244f
lib/cyborghood/base/config.rb | ||
---|---|---|
config = merge_into_default_config(config, spc_config)
|
||
end
|
||
|
||
config['bot_name'] = name
|
||
|
||
# create config object for easier access
|
||
@@config = config.to_ostruct.freeze
|
||
end
|
||
... | ... | |
if name.nil?
|
||
filename = CONFFILE_GLOBAL
|
||
else
|
||
filename = CONFFILE_BOT % name
|
||
filename = CONFFILE_BOT % name.downcase
|
||
end
|
||
filepath = File.join(File.expand_path(CFG_DIR), filename)
|
||
File.read(filepath)
|
||
... | ... | |
when 'global'
|
||
GlobalValidator
|
||
else
|
||
klass_name = type.capitalize + "Validator"
|
||
klass_name = type + "Validator"
|
||
if self.const_defined? klass_name
|
||
self.const_get klass_name
|
||
else
|
||
... | ... | |
# validate config with schema
|
||
parser = Kwalify::Yaml::Parser.new(validator)
|
||
def_data = parser.parse(def_data_raw, :filename => def_name, :untabify => true)
|
||
raise_if_validation_errors("#{type.capitalize} '#{def_name}'", parser.errors)
|
||
raise_if_validation_errors("#{type} '#{def_name}'", parser.errors)
|
||
|
||
def_data
|
||
rescue
|
||
... | ... | |
end
|
||
|
||
def self.load_default_config(type = "global")
|
||
filename = File.join(DATA_DIR, "default_config", type + ".yaml")
|
||
filename = File.join(DATA_DIR, "default_config", type.downcase + ".yaml")
|
||
default_config_raw = File.read(filename)
|
||
default_config = parse(':defaults:', type, default_config_raw, false)
|
||
default_config
|
||
... | ... | |
end
|
||
|
||
def self.load_schema(type = "global")
|
||
schema_file = File.join(DATA_DIR, "schema", type + ".yaml")
|
||
schema_file = File.join(DATA_DIR, "schema", type.downcase + ".yaml")
|
||
schema = YAML.load_file(schema_file)
|
||
|
||
# validate schema
|
Also available in: Unified diff
[evol] uncomplete MapMaker bot implementation (global cyborg classes, use of EventMachine with UNIX socket backend, configuration adjustments, ...) (refs #31)