Hobo::Config.settings is less crappy than .config ...
This commit is contained in:
parent
41a474dd77
commit
9ed95705f7
@ -1,14 +1,14 @@
|
|||||||
module Hobo
|
module Hobo
|
||||||
class Config
|
class Config
|
||||||
@@config = nil
|
@@settings = nil
|
||||||
class << self
|
class << self
|
||||||
# TODO Config.config is awkward
|
|
||||||
def config
|
def settings
|
||||||
@@config
|
@@settings
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_hash!(hash)
|
def from_hash!(hash)
|
||||||
@@config = hash_to_struct(hash)
|
@@settings = hash_to_struct(hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -1,17 +1,20 @@
|
|||||||
module Hobo
|
module Hobo
|
||||||
class Env
|
class Env
|
||||||
DIRS = [ File.expand_path('~/.hobo') ]
|
HOME = File.expand_path('~/.hobo')
|
||||||
CONFIG_FILE = { File.expand_path('~/.hobo/config.yml') => '/config/default.yml' }
|
CONFIG = { File.join(HOME, 'config.yml') => '/config/default.yml' }
|
||||||
FILES = CONFIG_FILE.merge({}) #additional files go mhia!
|
ENSURE = {
|
||||||
|
:files => CONFIG.merge({}), #additional files go mhia!
|
||||||
|
:dirs => [HOME] #additional dirs go mhia!
|
||||||
|
}
|
||||||
|
|
||||||
def ensure_directories
|
def ensure_directories
|
||||||
DIRS.each do |name|
|
ENSURE[:dirs].each do |name|
|
||||||
Dir.mkdir(name) unless File.exists?(name)
|
Dir.mkdir(name) unless File.exists?(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_files
|
def ensure_files
|
||||||
FILES.each do |target, default|
|
ENSURE[:files].each do |target, default|
|
||||||
File.copy(PROJECT_ROOT + default, target) unless File.exists?(target)
|
File.copy(PROJECT_ROOT + default, target) unless File.exists?(target)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -19,7 +22,7 @@ module Hobo
|
|||||||
def load_config
|
def load_config
|
||||||
ensure_directories
|
ensure_directories
|
||||||
ensure_files
|
ensure_files
|
||||||
parsed = yield(CONFIG_FILE.keys.first)
|
parsed = yield(CONFIG.keys.first)
|
||||||
Config.from_hash!(parsed)
|
Config.from_hash!(parsed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,7 +5,7 @@ class ConfigTest < Test::Unit::TestCase
|
|||||||
context "Hobo configuration" do
|
context "Hobo configuration" do
|
||||||
test "a hash source is converted to dot methods" do
|
test "a hash source is converted to dot methods" do
|
||||||
Hobo::Config.from_hash!(:a => {:b => 1})
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,19 +21,19 @@ class EnvTest < Test::Unit::TestCase
|
|||||||
dir_expectations
|
dir_expectations
|
||||||
file_expectations
|
file_expectations
|
||||||
@handler.load_config do |file|
|
@handler.load_config do |file|
|
||||||
assert_equal file, Hobo::Env::CONFIG_FILE.keys.first
|
assert_equal file, Hobo::Env::CONFIG.keys.first
|
||||||
{ :setting => 1 }
|
{ :setting => 1 }
|
||||||
end
|
end
|
||||||
assert_equal Hobo::Config.config.setting, 1
|
assert_equal Hobo::Config.settings.setting, 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO Expectations will fail if .hobo dir is present
|
#TODO Expectations will fail if .hobo dir is present
|
||||||
def dir_expectations
|
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
|
end
|
||||||
|
|
||||||
def file_expectations
|
def file_expectations
|
||||||
File.expects(:copy).times(Hobo::Env::FILES.length)
|
File.expects(:copy).times(Hobo::Env::ENSURE[:files].length)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user