Class: FastIgnore

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fast_ignore.rb,
lib/fast_ignore/version.rb,
lib/fast_ignore/patterns.rb,
lib/fast_ignore/candidate.rb,
lib/fast_ignore/rule_group.rb,
lib/fast_ignore/rule_groups.rb,
lib/fast_ignore/walkers/base.rb,
lib/fast_ignore/path_expander.rb,
lib/fast_ignore/builders/shebang.rb,
lib/fast_ignore/gitconfig_parser.rb,
lib/fast_ignore/global_gitignore.rb,
lib/fast_ignore/builders/gitignore.rb,
lib/fast_ignore/relative_candidate.rb,
lib/fast_ignore/matchers/within_dir.rb,
lib/fast_ignore/path_regexp_builder.rb,
lib/fast_ignore/walkers/file_system.rb,
lib/fast_ignore/gitignore_rule_group.rb,
lib/fast_ignore/matchers/unmatchable.rb,
lib/fast_ignore/gitignore_rule_builder.rb,
lib/fast_ignore/gitignore_rule_scanner.rb,
lib/fast_ignore/matchers/allow_any_dir.rb,
lib/fast_ignore/matchers/shebang_regexp.rb,
lib/fast_ignore/matchers/allow_path_regexp.rb,
lib/fast_ignore/matchers/ignore_path_regexp.rb,
lib/fast_ignore/builders/shebang_or_gitignore.rb,
lib/fast_ignore/gitignore_include_rule_builder.rb,
lib/fast_ignore/walkers/gitignore_collecting_file_system.rb

Defined Under Namespace

Modules: Builders, GlobalGitignore, Matchers, PathExpander, Walkers Classes: Candidate, Error, GitconfigParseError, GitconfigParser, GitignoreIncludeRuleBuilder, GitignoreRuleBuilder, GitignoreRuleGroup, GitignoreRuleScanner, PathRegexpBuilder, Patterns, RelativeCandidate, RuleGroup, RuleGroups

Constant Summary collapse

VERSION =
'0.17.4'

Instance Method Summary collapse

Constructor Details

#initialize(relative: false, root: nil, gitignore: :auto, follow_symlinks: false, **rule_group_builder_args) ⇒ FastIgnore

Returns a new instance of FastIgnore.



37
38
39
40
41
42
43
# File 'lib/fast_ignore.rb', line 37

def initialize(relative: false, root: nil, gitignore: :auto, follow_symlinks: false, **rule_group_builder_args)
  @root = "#{::File.expand_path(root.to_s, Dir.pwd)}/"
  @gitignore = gitignore
  @rule_group_builder_args = rule_group_builder_args
  @follow_symlinks = follow_symlinks
  @relative = relative
end

Instance Method Details

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

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
# File 'lib/fast_ignore.rb', line 45

def allowed?(path, directory: nil, content: nil, exists: nil, include_directories: false)
  walker.allowed?(
    path,
    root: @root,
    directory: directory,
    content: content,
    exists: exists,
    include_directories: include_directories
  )
end

#buildObject



69
70
71
72
73
74
75
76
# File 'lib/fast_ignore.rb', line 69

def build
  rule_groups = ::FastIgnore::RuleGroups.new(root: @root, gitignore: @gitignore, **@rule_group_builder_args)

  walker_class = @gitignore ? ::FastIgnore::Walkers::GitignoreCollectingFileSystem : ::FastIgnore::Walkers::FileSystem
  @walker = walker_class.new(rule_groups, follow_symlinks: @follow_symlinks)

  freeze
end

#each(&block) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/fast_ignore.rb', line 61

def each(&block)
  return enum_for(:each) unless block

  prefix = @relative ? '' : @root

  walker.each(@root, prefix, &block)
end

#to_procObject



57
58
59
# File 'lib/fast_ignore.rb', line 57

def to_proc
  method(:allowed?).to_proc
end