lib/doggy/shared_helpers.rb in doggy-0.2.0 vs lib/doggy/shared_helpers.rb in doggy-0.2.2
- old
+ new
@@ -30,7 +30,34 @@
puts prompt + " (Y/N)"
line = $stdin.readline.chomp.upcase
puts
line == "Y"
end
+
+ def self.error(msg)
+ puts "[ERROR] #{ msg }"
+ end
+
+ def self.find_root
+ File.dirname(find_file("Gemfile"))
+ end
+
+ def self.find_file(*names)
+ search_up(*names) do |filename|
+ return filename if File.file?(filename)
+ end
+ end
+
+ def self.search_up(*names)
+ previous = nil
+ current = File.expand_path(Pathname.pwd)
+
+ until !File.directory?(current) || current == previous
+ names.each do |name|
+ filename = File.join(current, name)
+ yield filename
+ end
+ current, previous = File.expand_path("..", current), current
+ end
+ end
end
end