2010-01-22 05:54:23 +00:00
|
|
|
module Hobo
|
2010-01-22 08:37:50 +00:00
|
|
|
module_function
|
2010-01-30 06:23:33 +00:00
|
|
|
|
2010-01-22 08:37:50 +00:00
|
|
|
def config
|
|
|
|
@@config
|
|
|
|
end
|
|
|
|
|
2010-01-24 08:09:15 +00:00
|
|
|
def config!(hash)
|
2010-01-30 06:03:07 +00:00
|
|
|
@@config = hash
|
2010-01-22 05:54:23 +00:00
|
|
|
end
|
2010-01-24 08:09:15 +00:00
|
|
|
|
2010-01-30 06:03:07 +00:00
|
|
|
def set_config_value(chain, val, cfg=@@config)
|
2010-01-24 08:09:15 +00:00
|
|
|
keys = chain.split('.')
|
2010-01-30 06:23:33 +00:00
|
|
|
|
2010-01-30 06:03:07 +00:00
|
|
|
return if keys.empty?
|
|
|
|
|
2010-01-30 06:23:33 +00:00
|
|
|
if keys.length == 1
|
|
|
|
# If we're out of keys and the value for this key is not a leaf blow up
|
|
|
|
raise InvalidSettingAlteration if cfg[keys.first.to_sym].is_a?(Hash)
|
|
|
|
|
|
|
|
# set the value and return if the value is a leaf
|
|
|
|
return cfg[keys.first.to_sym] = val
|
2010-01-24 08:09:15 +00:00
|
|
|
end
|
|
|
|
|
2010-01-30 06:23:33 +00:00
|
|
|
set_config_value(keys[1..-1].join('.'), val, cfg[keys.first.to_sym])
|
2010-01-24 08:09:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class InvalidSettingAlteration < StandardError; end
|
2010-01-22 05:54:23 +00:00
|
|
|
end
|