Module: RBS::FileFinder

Included in:
EnvironmentLoader
Defined in:
lib/rbs/file_finder.rb,
sig/file_finder.rbs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.each_file(path, immediate: nil, skip_hidden:, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rbs/file_finder.rb', line 7

def self.each_file(path, immediate: nil, skip_hidden:, &block)
  return enum_for((__method__ or raise), path, immediate: immediate, skip_hidden: skip_hidden) unless block

  case
  when path.file?
    yield path

  when path.directory?
    paths = Pathname.glob("#{path}/**/*.rbs")

    if skip_hidden
      paths.select! do |child|
        child.relative_path_from(path).ascend.drop(1).none? { _1.basename.to_s.start_with?("_") }
      end
    end
    paths.sort_by!(&:to_s)

    paths.each(&block)
  end
end

Instance Method Details

#self?void #self?Enumerator[Pathname, void]

Enumerate RBS files under path

When path is a file, it yields the path.

FileFinder.each_file(Pathname("foo.rbs")) {} # => yields `foo.rbs`

When path is a directory, it yields all .rbs files under the directory, recursively.

  • Skips files under directory starting with _, if skip_hidden is true
  • Yields files under directory starting with _ even if skip_hidden is true, when the _ directory is given explicitly, and immediate: is true
FileFinder.each_file(Pathname("sig"), skip_hidden: false) {} # => yields all `.rbs` files under `sig`
FileFinder.each_file(Pathname("sig"), skip_hidden: true) {} # => yields all `.rbs` files under `sig`, skips `_` directories

FileFinder.each_file(Pathname("_hidden"), skip_hidden: true) {}  # => yields all `.rbs` files under `_hidden`, skips other `_` directories

immediate keyword is unused and left for API compatibility.

Overloads:

  • #self?void

    This method returns an undefined value.

    Parameters:

    • path (Pathname)
    • immediate: (top)
    • skip_hidden: (boolish)
  • #self?Enumerator[Pathname, void]

    Parameters:

    • path (Pathname)
    • immediate: (top)
    • skip_hidden: (boolish)

    Returns:

    • (Enumerator[Pathname, void])

Yields:

Yield Parameters:

  • arg0 (Pathname)

Yield Returns:

  • (void)


25
26
# File 'sig/file_finder.rbs', line 25

def self?.each_file: (Pathname path, ?immediate: top, skip_hidden: boolish) { (Pathname) -> void } -> void
| (Pathname path, ?immediate: top, skip_hidden: boolish) -> Enumerator[Pathname, void]