Skip to content

Commit 944b9d3

Browse files
committed
Use Pathname to find Runfile.
1 parent 73a60c0 commit 944b9d3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

runx.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'pathname'
2+
13
class Task
24
def initialize(name, doc, block, dir)
35
@name = name
@@ -106,13 +108,11 @@ def method_missing(method, *args, &block)
106108
end
107109

108110
def find_runfile
109-
previous = nil
110-
dir = Dir.pwd
111-
while dir != previous
112-
runfile = File.join(dir, 'Runfile')
113-
return runfile.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) if File.exist?(runfile)
114-
previous = dir
115-
dir = File.expand_path(File.join(dir, '..'))
111+
Pathname.getwd.ascend do |path|
112+
runfile = File.join(path.to_s, 'Runfile')
113+
if File.exist?(runfile)
114+
return runfile.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
115+
end
116116
end
117117

118118
return nil

0 commit comments

Comments
 (0)