Class: FastIgnore::GitignoreIncludeRuleBuilder

Inherits:
GitignoreRuleBuilder show all
Defined in:
lib/fast_ignore/gitignore_include_rule_builder.rb

Instance Method Summary collapse

Methods inherited from GitignoreRuleBuilder

#anchored!, #blank!, #break!, #build, #dir_only!, #emit_any_dir, #emit_dir, #expand_rule_path!, #never_anchored!, #nothing_emitted?, #prefix, #process_backslash, #process_character_class, #process_character_class_range, #process_end, #process_rule, #process_slash, #process_star_end_after_slash, #process_two_stars

Constructor Details

#initialize(rule, expand_path_with: nil) ⇒ GitignoreIncludeRuleBuilder

Returns a new instance of GitignoreIncludeRuleBuilder.



5
6
7
8
9
# File 'lib/fast_ignore/gitignore_include_rule_builder.rb', line 5

def initialize(rule, expand_path_with: nil)
  super

  @negation = true
end

Instance Method Details

#build_as_parentObject



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

def build_as_parent
  anchored!
  dir_only!

  catch :abort_build do
    process_rule
    build_rule(child_file_rule: false)
  end
end

#build_child_file_ruleObject

rubocop:disable Metrics/MethodLength



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fast_ignore/gitignore_include_rule_builder.rb', line 43

def build_child_file_rule # rubocop:disable Metrics/MethodLength
  if @child_re.end_with?('/')
    @child_re.append_many_non_dir.append_dir if @dir_only
  else
    @child_re.append_dir
  end

  @child_re.prepend(prefix)

  if @negation
    ::FastIgnore::Matchers::AllowPathRegexp.new(@child_re.to_regexp, @anchored, false)
  else
    ::FastIgnore::Matchers::IgnorePathRegexp.new(@child_re.to_regexp, @anchored, false)
  end
end

#build_parent_dir_rulesObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fast_ignore/gitignore_include_rule_builder.rb', line 30

def build_parent_dir_rules
  return unless @negation

  if @anchored
    parent_pattern = @s.string.dup
    if parent_pattern.sub!(%r{/[^/]+/?\s*\z}, '/')
      ::FastIgnore::GitignoreIncludeRuleBuilder.new(parent_pattern).build_as_parent
    end
  else
    [::FastIgnore::Matchers::AllowAnyDir]
  end
end

#build_rule(child_file_rule: true) ⇒ Object



69
70
71
72
73
# File 'lib/fast_ignore/gitignore_include_rule_builder.rb', line 69

def build_rule(child_file_rule: true)
  @child_re ||= @re.dup # in case emit_end wasn't called

  [super(), *build_parent_dir_rules, (build_child_file_rule if child_file_rule)].compact
end

#emit_endObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/fast_ignore/gitignore_include_rule_builder.rb', line 19

def emit_end
  if @dir_only
    @child_re = @re.dup
    @re.append_end_anchor
  else
    @re.append_dir_or_end_anchor
  end

  break!
end

#negated!Object



11
12
13
# File 'lib/fast_ignore/gitignore_include_rule_builder.rb', line 11

def negated!
  @negation = false
end

#unmatchable_rule!Object



15
16
17
# File 'lib/fast_ignore/gitignore_include_rule_builder.rb', line 15

def unmatchable_rule!
  throw :abort_build, ::FastIgnore::Matchers::Unmatchable
end