Sha256: 95ba20de1f5f2e633b5ceab3b2224928ad27e4376d5b4ea2fafef4f8773a080d

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

module Homecoming
  class Find
    def initialize(filename, start_dir = Dir.pwd)
      @start_dir = start_dir
      @filename = filename
    end

    # 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"]
    #
    def files
      Traversal.new(@start_dir).map do |dir|
        filename = File.join(dir, @filename)
        File.exist?(filename) ? filename : nil
      end.compact.reverse
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
homecoming-0.1.1 lib/homecoming/find.rb