Method: PathList::Walkers::GitignoreCollectingFileSystem#each

Defined in:
lib/path_list/walkers/gitignore_collecting_file_system.rb

#each(parent_full_path, parent_relative_path, &block) ⇒ Object

rubocop:disable Metrics/MethodLength



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/path_list/walkers/gitignore_collecting_file_system.rb', line 22

def each(parent_full_path, parent_relative_path, &block) # rubocop:disable Metrics/MethodLength
  children = ::Dir.children(parent_full_path)
  @rule_groups.add_gitignore(parent_full_path) if children.include?('.gitignore')

  children.each do |filename|
    begin
      full_path = parent_full_path + filename
      relative_path = parent_relative_path + filename
      dir = ::File.lstat(full_path).directory?
      candidate = ::PathList::RootCandidate.new(full_path, filename, dir, nil)

      next unless @rule_groups.allowed_unrecursive?(candidate)

      if dir
        each(full_path + '/', relative_path + '/', &block)
      else
        yield relative_path
      end
    rescue ::Errno::ENOENT, ::Errno::EACCES, ::Errno::ENOTDIR, ::Errno::ELOOP, ::Errno::ENAMETOOLONG
      nil
    end
  end
end