Class: FastIgnore::Walkers::GitignoreCollectingFileSystem

Inherits:
Base
  • Object
show all
Defined in:
lib/fast_ignore/walkers/gitignore_collecting_file_system.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from FastIgnore::Walkers::Base

Instance Method Details

#allowed?(path, root: Dir.pwd, directory: nil, content: nil, exists: nil, include_directories: false) ⇒ Boolean

rubocop:disable Metrics/ParameterLists

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fast_ignore/walkers/gitignore_collecting_file_system.rb', line 6

def allowed?(path, root: Dir.pwd, directory: nil, content: nil, exists: nil, include_directories: false) # rubocop:disable Metrics/ParameterLists
  full_path = PathExpander.expand_path(path, root)
  return false unless full_path.start_with?(root)

  candidate = ::FastIgnore::Candidate.new(full_path, nil, directory, exists, content)

  begin
    return false if !include_directories && directory?(full_path, directory)
  rescue ::Errno::ENOENT, ::Errno::EACCES, ::Errno::ELOOP, ::Errno::ENAMETOOLONG
    # nil
  end

  return false unless candidate.exists?

  @rule_groups.add_gitignore_to_root(full_path)
  @rule_groups.allowed_recursive?(candidate)
end

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

rubocop:disable Metrics/MethodLength



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

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|
    full_path = parent_full_path + filename
    dir = directory?(full_path, nil)
    candidate = ::FastIgnore::Candidate.new(full_path, filename, dir, true, nil)

    next unless @rule_groups.allowed_unrecursive?(candidate)

    relative_path = parent_relative_path + filename

    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