lib/ztk/locator.rb
# 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.
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.
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 .
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
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
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.
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 .
The expanded path to the located entry.
The expanded path to the located entry .
String
args
<not_specific>
<not_specific>
args A string or array of strings to attempt to locate.
args A string or array of strings to attempt to locate .