Sha256: 57029b59fd9dc91e9ed3ea93cf52d34e158cac9b36ea047584ac78578f4f2ac4
Contents?: true
Size: 980 Bytes
Versions: 27
Compression:
Stored size: 980 Bytes
Contents
module ZTK # Locator Error Class # # @author Zachary Patten <zachary AT jovelabs DOT com> class LocatorError < Error; end # @author Zachary Patten <zachary AT jovelabs DOT com> class Locator class << self # Locate a file or directory # # Attempts to locate the file or directory supplied, starting with # the current working directory and crawling it up looking for a match # at each step of the way. # # @param [String,Array<String>] args A string or array of strings to # attempt to locate. # # @return [String] The expanded path to the located entry. def find(*args) pwd = Dir.pwd.split(File::SEPARATOR) (pwd.length - 1).downto(0) do |i| candidate = File.expand_path(File.join(pwd[0..i], args)) return candidate if File.exists?(candidate) end raise LocatorError, "Could not locate '#{File.join(args)}'!" end end end end
Version data entries
27 entries across 27 versions & 1 rubygems