Class: Homecoming::Find

Inherits:
Object
  • Object
show all
Defined in:
lib/homecoming/find.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, start_dir = Dir.pwd) ⇒ Find

Returns a new instance of Find.



3
4
5
6
# File 'lib/homecoming/find.rb', line 3

def initialize(filename, start_dir = Dir.pwd)
  @start_dir = start_dir
  @filename = filename
end

Instance Method Details

#filesObject

Returns all found files with the given filename in the current and all parent directories.

# Given the following directory structure:

/
  home/
    rrrene/
      projects/
        your_project/
          .yourconfig
      .yourconfig

Homecoming.find(".yourconfig", "/home/rrrene/projects/your_project")
# => ["/home/rrrene/.yourconfig",
      "/home/rrrene/projects/your_project/.yourconfig"]


25
26
27
28
29
30
# File 'lib/homecoming/find.rb', line 25

def files
  Traversal.new(@start_dir).map do |dir|
    filename = File.join(dir, @filename)
    File.exist?(filename) ? filename : nil
  end.compact.reverse
end