From b92ddb86124108092e27fe63ae62e7ee4fe5cf66 Mon Sep 17 00:00:00 2001 From: Markus Prinz Date: Mon, 19 May 2008 01:40:29 +0200 Subject: [PATCH 1/2] Add URI detection to install task, and make sure we don't append ".thor" to URIs --- lib/thor/runner.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/thor/runner.rb b/lib/thor/runner.rb index 262945a62..651c400b2 100644 --- a/lib/thor/runner.rb +++ b/lib/thor/runner.rb @@ -30,6 +30,8 @@ def install(name, opts = {}) raise Error, "Error opening file `#{name}'" end + is_uri = File.exist?(name) ? false : true + puts "Your Thorfile contains: " puts contents print "Do you wish to continue [y/N]? " @@ -39,7 +41,7 @@ def install(name, opts = {}) constants = Thor::Util.constants_in_contents(contents) - name = name =~ /\.thor$/ ? name : "#{name}.thor" + name = name =~ /\.thor$/ || is_uri ? name : "#{name}.thor" as = opts["as"] || begin first_line = contents.split("\n")[0] From aa042e15810dd29078429b30dc71ce5eefec822c Mon Sep 17 00:00:00 2001 From: Markus Prinz Date: Mon, 19 May 2008 02:06:17 +0200 Subject: [PATCH 2/2] Optionally store the absolute path to a thor file on install --- lib/thor/runner.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/thor/runner.rb b/lib/thor/runner.rb index 651c400b2..8b33054f7 100644 --- a/lib/thor/runner.rb +++ b/lib/thor/runner.rb @@ -19,7 +19,7 @@ def initialize_thorfiles(relevant_to = nil) map "-T" => :list, "-i" => :install, "-u" => :update desc "install NAME", "install a Thor file into your system tasks, optionally named for future updates" - method_options :as => :optional + method_options :as => :optional, :absolute => :boolean def install(name, opts = {}) initialize_thorfiles begin @@ -60,7 +60,9 @@ def install(name, opts = {}) FileUtils.touch(yaml_file) yaml = thor_yaml - yaml[as] = {:filename => Digest::MD5.hexdigest(name + as), :location => name, :constants => constants} + location = (opts["absolute"] && !is_uri) ? File.expand_path(name) : name + + yaml[as] = {:filename => Digest::MD5.hexdigest(name + as), :location => location, :constants => constants} save_yaml(yaml)