Hobo::Config.settings -> Hobo.config

This commit is contained in:
John Bender 2010-01-22 00:37:50 -08:00
parent c59b189bfa
commit 7cd249ec63
4 changed files with 18 additions and 18 deletions

View File

@ -1,23 +1,22 @@
module Hobo
module_function
def config
@@config
end
def config_from_hash!(hash)
@@config = Config.from_hash(hash)
end
class Config
@@settings = nil
class << self
def settings
@@settings
end
def from_hash!(hash)
@@settings = hash_to_struct(hash)
end
private
def hash_to_struct(value)
def from_hash(value)
return value unless value.instance_of?(Hash)
result = value.inject({}) do |acc, pair|
acc[pair.first] = hash_to_struct(pair.last)
acc[pair.first] = from_hash(pair.last)
acc
end

View File

@ -23,7 +23,7 @@ module Hobo
ensure_directories
ensure_files
parsed = yield(CONFIG.keys.first)
Config.from_hash!(parsed)
Hobo.config_from_hash!(parsed)
end
end
end

View File

@ -4,8 +4,8 @@ class ConfigTest < Test::Unit::TestCase
context "Hobo configuration" do
test "a hash source is converted to dot methods" do
Hobo::Config.from_hash!(:a => {:b => 1})
assert_equal Hobo::Config.settings.a.b, 1
Hobo.config_from_hash!(:a => {:b => 1})
assert_equal Hobo.config.a.b, 1
end
end
end

View File

@ -24,7 +24,8 @@ class EnvTest < Test::Unit::TestCase
assert_equal file, Hobo::Env::CONFIG.keys.first
{ :setting => 1 }
end
assert_equal Hobo::Config.settings.setting, 1
assert_equal Hobo.config.setting, 1
end
end