walks the parent folders to find the dotfile
This commit is contained in:
parent
b11bad4788
commit
62c6d91a24
|
@ -8,6 +8,7 @@ module Hobo
|
|||
:files => CONFIG.merge({}), #additional files go mhia!
|
||||
:dirs => [HOME] #additional dirs go mhia!
|
||||
}
|
||||
PATH_CHUNK_REGEX = /\/[^\/]+$/
|
||||
|
||||
class << self
|
||||
def load!
|
||||
|
@ -37,11 +38,19 @@ module Hobo
|
|||
end
|
||||
|
||||
def load_uuid!
|
||||
@@persisted_uuid = nil
|
||||
if File.exists?(Hobo.config[:dotfile_name])
|
||||
@@persisted_uuid = load_dotfile
|
||||
end
|
||||
|
||||
def load_dotfile(dir=Dir.pwd)
|
||||
return nil if dir.empty?
|
||||
|
||||
file = "#{dir}/#{Hobo.config[:dotfile_name]}"
|
||||
if File.exists?(file)
|
||||
# TODO check multiple lines after the first for information
|
||||
@@persisted_uuid = File.open(Hobo.config[:dotfile_name], 'r').first
|
||||
return File.open(file, 'r').first
|
||||
end
|
||||
|
||||
load_dotfile(dir.sub(PATH_CHUNK_REGEX, ''))
|
||||
end
|
||||
|
||||
def persisted_uuid
|
||||
|
|
|
@ -71,13 +71,27 @@ class EnvTest < Test::Unit::TestCase
|
|||
assert_equal Hobo::Env.persisted_uuid, nil
|
||||
end
|
||||
|
||||
test "should walk the parent directories looking for the dotfile" do
|
||||
Hobo.config! hobo_mock_config
|
||||
#Expects exists with the current directory and .hobo
|
||||
File.expects(:exists?).with(dotfile).returns(false)
|
||||
File.expects(:exists?).with(dotfile(Dir.pwd.sub(Hobo::Env::PATH_CHUNK_REGEX, ''))).returns(true)
|
||||
File.expects(:open).returns(['foo'])
|
||||
Hobo::Env.load_uuid!
|
||||
assert_equal Hobo::Env.persisted_uuid, 'foo'
|
||||
end
|
||||
|
||||
def dot_file_expectation
|
||||
File.expects(:exists?).at_least_once.returns(true)
|
||||
File.expects(:open).with('.hobo', 'r').returns(['foo'])
|
||||
File.expects(:open).with(dotfile, 'r').returns(['foo'])
|
||||
end
|
||||
|
||||
def config_file_expectation
|
||||
YAML.expects(:load_file).with(Hobo::Env::CONFIG.keys.first).returns(hobo_mock_config)
|
||||
end
|
||||
|
||||
def dotfile(dir=Dir.pwd)
|
||||
"#{dir}/#{hobo_mock_config[:dotfile_name]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue