Class: PathList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/path_list.rb,
lib/path_list/version.rb,
lib/path_list/patterns.rb,
lib/path_list/backports.rb,
lib/path_list/rule_group.rb,
lib/path_list/rule_groups.rb,
lib/path_list/rule_builder.rb,
lib/path_list/root_candidate.rb,
lib/path_list/global_gitignore.rb,
lib/path_list/relative_candidate.rb,
lib/path_list/matchers/within_dir.rb,
lib/path_list/path_regexp_builder.rb,
lib/path_list/walkers/file_system.rb,
lib/path_list/gitignore_rule_group.rb,
lib/path_list/matchers/unmatchable.rb,
lib/path_list/gitignore_rule_builder.rb,
lib/path_list/gitignore_rule_scanner.rb,
lib/path_list/matchers/allow_any_dir.rb,
lib/path_list/matchers/shebang_regexp.rb,
lib/path_list/matchers/allow_path_regexp.rb,
lib/path_list/matchers/ignore_path_regexp.rb,
lib/path_list/gitignore_include_rule_builder.rb,
lib/path_list/walkers/gitignore_collecting_file_system.rb

Defined Under Namespace

Modules: Backports, GlobalGitignore, Matchers, RuleBuilder, Walkers Classes: Error, GitignoreIncludeRuleBuilder, GitignoreRuleBuilder, GitignoreRuleGroup, GitignoreRuleScanner, PathRegexpBuilder, Patterns, RelativeCandidate, RootCandidate, RuleGroup, RuleGroups

Constant Summary collapse

VERSION =
'0.16'

Instance Method Summary collapse

Constructor Details

#initialize(root: nil, gitignore: :auto, **rule_group_builder_args) ⇒ PathList

:nocov:



38
39
40
41
42
43
44
45
# File 'lib/path_list.rb', line 38

def initialize(root: nil, gitignore: :auto, **rule_group_builder_args)
  @root = "#{::File.expand_path(root.to_s, Dir.pwd)}/"
  rule_groups = ::PathList::RuleGroups.new(root: @root, gitignore: gitignore, **rule_group_builder_args)

  walker_class = gitignore ? ::PathList::Walkers::GitignoreCollectingFileSystem : ::PathList::Walkers::FileSystem
  @walker = walker_class.new(rule_groups)
  freeze
end

Instance Method Details

#allowed?(path, directory: nil, content: nil) ⇒ Boolean Also known as: ===

Returns:

  • (Boolean)


47
48
49
# File 'lib/path_list.rb', line 47

def allowed?(path, directory: nil, content: nil)
  @walker.allowed?(path, directory: directory, content: content)
end

#each(root = ::Dir.pwd, &block) ⇒ Object



56
57
58
59
60
61
# File 'lib/path_list.rb', line 56

def each(root = ::Dir.pwd, &block)
  return enum_for(:each, root) unless block_given?

  root = "#{::File.expand_path(root.to_s, Dir.pwd)}/"
  @walker.each(root, '', &block)
end

#to_procObject



52
53
54
# File 'lib/path_list.rb', line 52

def to_proc
  method(:allowed?).to_proc
end