Sha256: 32159072578ec97e8eaf3dd5bc47f79454e20e6aa257e682ae9356bcd5b175ad

Contents?: true

Size: 1.08 KB

Versions: 7083

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'pathname'

module RuboCop
  # Common methods for finding files.
  module FileFinder
    def self.root_level=(level)
      @root_level = level
    end

    def self.root_level?(path)
      @root_level == path.to_s
    end

    def find_file_upwards(filename, start_dir, use_home: false)
      traverse_files_upwards(filename, start_dir, use_home) do |file|
        # minimize iteration for performance
        return file if file
      end
    end

    def find_files_upwards(filename, start_dir, use_home: false)
      files = []
      traverse_files_upwards(filename, start_dir, use_home) do |file|
        files << file
      end
      files
    end

    private

    def traverse_files_upwards(filename, start_dir, use_home)
      Pathname.new(start_dir).expand_path.ascend do |dir|
        break if FileFinder.root_level?(dir)

        file = dir + filename
        yield(file.to_s) if file.exist?
      end

      return unless use_home && ENV.key?('HOME')

      file = File.join(Dir.home, filename)
      yield(file) if File.exist?(file)
    end
  end
end

Version data entries

7,083 entries across 7,077 versions & 26 rubygems

Version Path
cybrid_api_organization_ruby-0.123.274 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.274 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.273 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_bank_ruby-0.123.273 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.273 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_bank_ruby-0.123.272 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.272 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.272 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.271 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_bank_ruby-0.123.271 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.271 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_bank_ruby-0.123.268 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.268 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.268 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_bank_ruby-0.123.267 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.267 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.267 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_bank_ruby-0.123.266 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.266 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.266 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb