Sha256: 32159072578ec97e8eaf3dd5bc47f79454e20e6aa257e682ae9356bcd5b175ad

Contents?: true

Size: 1.08 KB

Versions: 6830

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

6,830 entries across 6,824 versions & 25 rubygems

Version Path
cybrid_api_organization_ruby-0.123.186 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.186 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.185 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.185 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.184 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.184 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.183 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.183 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
ory-client-1.16.5 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
ory-client-1.16.4 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_id_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb
cybrid_api_organization_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/file_finder.rb