diff --git a/lib/hobo/config.rb b/lib/hobo/config.rb index 4bbc7c332..823b8c7c9 100644 --- a/lib/hobo/config.rb +++ b/lib/hobo/config.rb @@ -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 diff --git a/lib/hobo/env.rb b/lib/hobo/env.rb index a4af39d8f..8025d29fc 100644 --- a/lib/hobo/env.rb +++ b/lib/hobo/env.rb @@ -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 diff --git a/test/hobo/config_test.rb b/test/hobo/config_test.rb index 268f3d6c3..58463f754 100644 --- a/test/hobo/config_test.rb +++ b/test/hobo/config_test.rb @@ -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 diff --git a/test/hobo/env_test.rb b/test/hobo/env_test.rb index faef49be6..41b747810 100644 --- a/test/hobo/env_test.rb +++ b/test/hobo/env_test.rb @@ -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