Class: ZTK::Locator
- Inherits:
-
Object
- Object
- ZTK::Locator
- Defined in:
- lib/ztk/locator.rb
Overview
Class Method Summary (collapse)
-
+ (String) find(*args)
Locate a file or directory.
-
+ (String) root
Returns the root for the filesystem we are operating on.
Class Method Details
+ (String) find(*args)
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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ztk/locator.rb', line 23 def find(*args) pwd = Dir.pwd.split(File::SEPARATOR) (pwd.length - 1).downto(0) do |i| candidate = File.(File.join(pwd[0..i], args)) return candidate if File.exists?(candidate) end raise LocatorError, "Could not locate '#{File.join(args)}'!" end |
+ (String) root
Returns the root for the filesystem we are operating on. Ignores mount boundries on *nix.
For all flavors of *nix this should always return "/".
Windows should expect something similar to "C:\".
43 44 45 |
# File 'lib/ztk/locator.rb', line 43 def root Dir.pwd.split(File::SEPARATOR).first end |