From 9ed95705f795b1928f6c8c96997c61080029e12a Mon Sep 17 00:00:00 2001 From: John Bender Date: Thu, 21 Jan 2010 23:57:43 -0800 Subject: [PATCH] Hobo::Config.settings is less crappy than .config ... --- lib/hobo/config.rb | 10 +++++----- lib/hobo/env.rb | 17 ++++++++++------- test/hobo/config_test.rb | 2 +- test/hobo/env_test.rb | 8 ++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/hobo/config.rb b/lib/hobo/config.rb index 5a789d115..4bbc7c332 100644 --- a/lib/hobo/config.rb +++ b/lib/hobo/config.rb @@ -1,14 +1,14 @@ module Hobo class Config - @@config = nil + @@settings = nil class << self - # TODO Config.config is awkward - def config - @@config + + def settings + @@settings end def from_hash!(hash) - @@config = hash_to_struct(hash) + @@settings = hash_to_struct(hash) end private diff --git a/lib/hobo/env.rb b/lib/hobo/env.rb index f2d65d061..a4af39d8f 100644 --- a/lib/hobo/env.rb +++ b/lib/hobo/env.rb @@ -1,17 +1,20 @@ module Hobo class Env - DIRS = [ File.expand_path('~/.hobo') ] - CONFIG_FILE = { File.expand_path('~/.hobo/config.yml') => '/config/default.yml' } - FILES = CONFIG_FILE.merge({}) #additional files go mhia! - + HOME = File.expand_path('~/.hobo') + CONFIG = { File.join(HOME, 'config.yml') => '/config/default.yml' } + ENSURE = { + :files => CONFIG.merge({}), #additional files go mhia! + :dirs => [HOME] #additional dirs go mhia! + } + def ensure_directories - DIRS.each do |name| + ENSURE[:dirs].each do |name| Dir.mkdir(name) unless File.exists?(name) end end def ensure_files - FILES.each do |target, default| + ENSURE[:files].each do |target, default| File.copy(PROJECT_ROOT + default, target) unless File.exists?(target) end end @@ -19,7 +22,7 @@ module Hobo def load_config ensure_directories ensure_files - parsed = yield(CONFIG_FILE.keys.first) + parsed = yield(CONFIG.keys.first) Config.from_hash!(parsed) end end diff --git a/test/hobo/config_test.rb b/test/hobo/config_test.rb index 470ec8bc9..268f3d6c3 100644 --- a/test/hobo/config_test.rb +++ b/test/hobo/config_test.rb @@ -5,7 +5,7 @@ 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.config.a.b, 1 + assert_equal Hobo::Config.settings.a.b, 1 end end end diff --git a/test/hobo/env_test.rb b/test/hobo/env_test.rb index 7cb4273bf..1cf183d55 100644 --- a/test/hobo/env_test.rb +++ b/test/hobo/env_test.rb @@ -21,19 +21,19 @@ class EnvTest < Test::Unit::TestCase dir_expectations file_expectations @handler.load_config do |file| - assert_equal file, Hobo::Env::CONFIG_FILE.keys.first + assert_equal file, Hobo::Env::CONFIG.keys.first { :setting => 1 } end - assert_equal Hobo::Config.config.setting, 1 + assert_equal Hobo::Config.settings.setting, 1 end end #TODO Expectations will fail if .hobo dir is present def dir_expectations - Dir.expects(:mkdir).times(Hobo::Env::DIRS.length).returns nil + Dir.expects(:mkdir).times(Hobo::Env::ENSURE[:dirs].length).returns nil end def file_expectations - File.expects(:copy).times(Hobo::Env::FILES.length) + File.expects(:copy).times(Hobo::Env::ENSURE[:files].length) end end