vagrant/lib/hobo/config.rb

30 lines
651 B
Ruby
Raw Normal View History

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
def config!(hash)
@@config = hash
2010-01-22 05:54:23 +00:00
end
def set_config_value(chain, val, cfg=@@config)
keys = chain.split('.')
2010-01-30 06:23:33 +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
end
2010-01-30 06:23:33 +00:00
set_config_value(keys[1..-1].join('.'), val, cfg[keys.first.to_sym])
end
class InvalidSettingAlteration < StandardError; end
2010-01-22 05:54:23 +00:00
end