module PathList::RuleBuilder

Public Class Methods

build(rule, allow, format, root) click to toggle source

:nocov:

# File lib/path_list/rule_builder.rb, line 10
def build(rule, allow, format, root)
  if rule.delete_prefix!('#!:')
    shebang_rules(rule, allow)
  else
    gitignore_rules(rule, allow, format, root)
  end
end

Private Class Methods

gitignore_rules(rule, allow, format, root) click to toggle source
# File lib/path_list/rule_builder.rb, line 33
def gitignore_rules(rule, allow, format, root)
  if allow
    ::PathList::GitignoreIncludeRuleBuilder.new(rule, expand_path_with: (root if format == :expand_path)).build
  else
    ::PathList::GitignoreRuleBuilder.new(rule).build
  end
end
shebang_rules(shebang, allow) click to toggle source

how long can a shebang be? www.in-ulm.de/~mascheck/various/shebang/ Theoretically the limit is 65536, but that feels utterly unreasonable

# File lib/path_list/rule_builder.rb, line 23
def shebang_rules(shebang, allow)
  shebang.strip!
  pattern = /\A#![^\n]{,#{510 - shebang.length}}\b#{::Regexp.escape(shebang)}\b/i
  rule = ::PathList::Matchers::ShebangRegexp.new(pattern, allow)
  return rule unless allow

  # also allow all directories in case they include a file with the matching shebang file
  [::PathList::Matchers::AllowAnyDir, rule]
end