class FastIgnore::GitignoreIncludeRuleBuilder

Public Class Methods

new(rule, file_path, expand_path_from = nil) click to toggle source

:nocov:

Calls superclass method
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 9
def initialize(rule, file_path, expand_path_from = nil)
  super(rule, file_path)

  @parent_segments = []
  @negation = true
  @expand_path_from = expand_path_from
end

Public Instance Methods

build_child_file_rule() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 80
def build_child_file_rule
  # Regexp::IGNORECASE = 1
  ::FastIgnore::Rule.new(@re.append_dir.to_regexp, @negation, anchored_or_file_path, false)
end
build_parent_dir_rule() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 75
def build_parent_dir_rule
  # Regexp::IGNORECASE = 1
  ::FastIgnore::Rule.new(::Regexp.new(parent_dir_re, 1), true, anchored_or_file_path, true)
end
build_rule() click to toggle source
Calls superclass method
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 85
def build_rule
  joined_re = ::FastIgnore::GitignoreRuleRegexpBuilder.new
  joined_re.append(@parent_segments.join('/'))
  joined_re.append_dir unless @parent_segments.empty?
  joined_re.append(@re)
  @re = joined_re

  rules = [super, build_parent_dir_rule]
  (rules << build_child_file_rule) if @dir_only
  rules
end
emit_dir() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 39
def emit_dir
  anchored!

  @parent_segments << @re
  @re = ::FastIgnore::GitignoreRuleRegexpBuilder.new
end
emit_end() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 46
def emit_end
  @dir_only || @re.append_end_dir_or_anchor
  break!
end
expand_rule_path() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 17
def expand_rule_path
  anchored! unless @s.match?(/\*/)
  return unless @s.match?(%r{(?:[~/]|\.{1,2}/|.*/\.\./)})

  dir_only! if @s.match?(%r{.*/\s*\z})
  @s.string.replace(::File.expand_path(@s.rest))
  @s.string.delete_prefix!(@expand_path_from)
  @s.pos = 0
end
negated!() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 27
def negated!
  @negation = false
end
nothing_emitted?() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 35
def nothing_emitted?
  @re.empty? && @parent_segments.empty?
end
parent_dir_re() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 51
def parent_dir_re # rubocop:disable Metrics/MethodLength
  segment_joins_count = @parent_segments.length
  parent_prefix = if @file_path
    segment_joins_count += @file_path.escaped_segments_length

    if @anchored
      "\\A#{@file_path.escaped_segments_joined}"
    else
      "\\A#{@file_path.escaped_segments_joined}(?:.*/)?"
    end
  else
    prefix
  end

  out = parent_prefix.dup
  unless @parent_segments.empty?
    out << '(?:'
    out << @parent_segments.join('/(?:')
    out << '/'
  end
  out << (')?' * segment_joins_count)
  out
end
process_rule() click to toggle source
Calls superclass method
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 97
def process_rule
  expand_rule_path if @expand_path_from
  super
end
unmatchable_rule!() click to toggle source
# File lib/fast_ignore/gitignore_include_rule_builder.rb, line 31
def unmatchable_rule!
  throw :abort_build, ::FastIgnore::UnmatchableRule
end