commit d9a83d4f913cbf0549a0bfb7041d75d4112a666f
parent d6431b2a19b04d840e3e209ea3e4b3d8d36066e6
Author: Whyme Lyu <callme5long@gmail.com>
Date: Thu, 16 May 2013 23:50:52 +0800
sup-config should expand ~ in path
Diffstat:
4 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/bin/sup-config b/bin/sup-config
@@ -36,6 +36,8 @@ def build_cmd cmd
end
def add_source
+ require "sup/util/uri"
+
type = nil
say "Ok, adding a new source."
@@ -69,7 +71,7 @@ def add_source
end
uri = begin
- URI::Generic.build components
+ Redwood::Util::Uri.build components
rescue URI::Error => e
say "Whoopsie! I couldn't build a URI from that: #{e.message}"
if axe_yes("Try again?") then next else return end
diff --git a/lib/sup/util/path.rb b/lib/sup/util/path.rb
@@ -0,0 +1,9 @@
+module Redwood
+ module Util
+ module Path
+ def self.expand(path)
+ ::File.expand_path(path)
+ end
+ end
+ end
+end
diff --git a/lib/sup/util/uri.rb b/lib/sup/util/uri.rb
@@ -0,0 +1,15 @@
+require "uri"
+
+require "sup/util/path"
+
+module Redwood
+ module Util
+ module Uri
+ def self.build(components)
+ components = components.dup
+ components[:path] = Path.expand(components[:path])
+ ::URI::Generic.build(components)
+ end
+ end
+ end
+end
diff --git a/test/unit/util/uri.rb b/test/unit/util/uri.rb
@@ -0,0 +1,19 @@
+require "test_helper.rb"
+
+require "sup/util/uri"
+
+describe Redwood::Util::Uri do
+ describe ".build" do
+ it "builds uri from hash" do
+ components = {:path => "/var/mail/foo", :scheme => "mbox"}
+ uri = Redwood::Util::Uri.build(components)
+ uri.to_s.must_equal "mbox:/var/mail/foo"
+ end
+
+ it "expands ~ in path" do
+ components = {:path => "~/foo", :scheme => "maildir"}
+ uri = Redwood::Util::Uri.build(components)
+ uri.to_s.must_equal "maildir:#{ENV["HOME"]}/foo"
+ end
+ end
+end