Module: ParentPaths
- Defined in:
- lib/parent_paths.rb,
lib/parent_paths/version.rb
Constant Summary collapse
- VERSION =
'0.0.3'
Class Method Summary collapse
-
.find(start = nil, &criteria) ⇒ Object
From the given starting path, scan upward through the file hierachy until a particular criteria is met.
-
.find_owner(filename, start = nil) ⇒ Object
From the given starting path, scan upward through the file hierachy until a particular filename is discovered.
Class Method Details
.find(start = nil, &criteria) ⇒ Object
From the given starting path, scan upward through the file hierachy until a particular criteria is met. The criteria is determined by a block that receives the path of the next directory in the hierarchy.
If a starting path is not provided, it is assumed to be the path of the file that calls this method.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/parent_paths.rb', line 11 def self.find(start = nil, &criteria) start ||= caller_path if criteria.call(start) return start else parent = Pathname.new(start).parent.to_s if start == parent nil else find parent, &criteria end end end |
.find_owner(filename, start = nil) ⇒ Object
From the given starting path, scan upward through the file hierachy until a particular filename is discovered.
If a starting path is not provided, it is assumed to be the path of the file that calls this method.
30 31 32 33 |
# File 'lib/parent_paths.rb', line 30 def self.find_owner(filename, start = nil) start ||= caller_path find(start) { |path| File.exist?(File.join(path, filename)) } end |