Skip to content

Commit

Permalink
Use full paths for bundle path and config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Fiorini committed Nov 26, 2010
1 parent 9bab810 commit f07bc5d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/vimmer/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class Settings


def initialize
@config = load_config(config_file)
@config = defaults.merge(load_config(config_file))
end


def [](key)
value = @config[key.to_s]
if value && (File.directory?(value) || File.file?(value))
value = File.expand_path(@config[key.to_s])
if value && File.exists?(value)
Pathname.new(value)
else
value
Expand Down Expand Up @@ -85,12 +85,18 @@ def write_to_manifest(hash)
end

def load_config(config_file)
if File.exist?(config_file)
config_file = File.expand_path(config_file)
if config_file && File.exist?(config_file.to_s)
YAML.load_file(config_file)
else
{}
end
end


def defaults
{ "bundle_path" => "~/.vim/bundle" }
end

end
end
15 changes: 15 additions & 0 deletions spec/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@
File.read(settings.config_file).should =~ /bundle_path: ~\/.vim\/bundle/
end


it "expands the path when calling bundle_path" do
ENV['VIMMER_HOME'] = vimmer_home.to_s

bundle_path = app_root.join("lib", "..", "tmp", "bundle")
File.open(vimmer_home.join("config").to_s, "w") do |f|
f << "bundle_path: #{bundle_path}"
end

Vimmer::Settings.new[:bundle_path].should == File.expand_path(bundle_path)

ENV['VIMMER_HOME'] = nil
end


end
6 changes: 5 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
config.mock_with :mocha

def app_root
Pathname.new(File.join(__FILE__, "..", "tmp", ".vimmer"))
Pathname.new(File.join(File.dirname(__FILE__), ".."))
end

def vimmer_home
app_root.join("tmp", ".vimmer")
end


Expand Down

0 comments on commit f07bc5d

Please sign in to comment.