Module: ParentPaths

Defined in:
lib/parent_paths.rb,
lib/parent_paths/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.scan(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
24
# File 'lib/parent_paths.rb', line 11

def self.scan(start = nil, &criteria)
  start ||= caller_path
  start = Pathname.new(start)
  if criteria.call(start)
    return start
  else
    parent = start.parent
    if start == parent
      nil
    else
      scan parent, &criteria
    end
  end
end

.scan_for_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.



31
32
33
34
# File 'lib/parent_paths.rb', line 31

def self.scan_for_owner(filename, start = nil)
  start ||= caller_path
  scan(start) { |pathname| File.exist?(pathname + filename) }
end