class PathList::GitignoreRuleBuilder
Public Class Methods
new(rule)
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 5 def initialize(rule) @re = ::PathList::PathRegexpBuilder.new @s = ::PathList::GitignoreRuleScanner.new(rule) @negation = false @anchored = false @dir_only = false end
Public Instance Methods
anchored!()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 30 def anchored! @anchored ||= true end
blank!()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 18 def blank! throw :abort_build, [] end
break!()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 14 def break! throw :break end
build()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 180 def build catch :abort_build do blank! if @s.hash? negated! if @s.exclamation_mark? process_rule @anchored = false if @anchored == :never build_rule end end
build_rule()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 171 def build_rule @re.prepend(prefix) if @negation ::PathList::Matchers::AllowPathRegexp.new(@re.to_regexp, @anchored, @dir_only) else ::PathList::Matchers::IgnorePathRegexp.new(@re.to_regexp, @anchored, @dir_only) end end
dir_only!()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 38 def dir_only! @dir_only = true end
emit_any_dir()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 51 def emit_any_dir anchored! @re.append_any_dir end
emit_dir()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 46 def emit_dir anchored! @re.append_dir end
emit_end()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 56 def emit_end @re.append_end_anchor break! end
negated!()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 26 def negated! @negation = true end
never_anchored!()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 34 def never_anchored! @anchored = :never end
nothing_emitted?()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 42 def nothing_emitted? @re.empty? end
prefix()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 160 def prefix out = ::PathList::PathRegexpBuilder.new if @anchored out.append_start_anchor else out.append_dir_or_start_anchor end out end
process_backslash()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 61 def process_backslash return unless @s.backslash? @re.append_escaped(@s.next_character) || unmatchable_rule! end
process_character_class()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 117 def process_character_class # rubocop:disable Metrics/MethodLength return unless @s.character_class_start? @re.append_character_class_open @re.append_character_class_negation if @s.character_class_negation? unmatchable_rule! if @s.character_class_end? until @s.character_class_end? next if process_backslash next @re.append_character_class_dash if @s.dash? next if @re.append_escaped(@s.character_class_literal) unmatchable_rule! end @re.append_character_class_close end
process_end()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 135 def process_end blank! if nothing_emitted? emit_end end
process_rule()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 141 def process_rule # rubocop:disable Metrics/MethodLength, Metrics/AbcSize anchored! if @s.slash? catch :break do loop do next if process_backslash next if process_slash next if process_two_stars next @re.append_any_non_dir if @s.star? next @re.append_one_non_dir if @s.question_mark? next if process_character_class next if @re.append_escaped(@s.literal) next if @re.append_escaped(@s.significant_whitespace) process_end end end end
process_slash()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 85 def process_slash return unless @s.slash? return dir_only! if @s.end? return unmatchable_rule! if @s.slash? emit_dir process_star_end_after_slash end
process_star_end_after_slash()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 67 def process_star_end_after_slash # rubocop:disable Metrics/MethodLength if @s.star_end? @re.append_many_non_dir emit_end elsif @s.two_star_end? break! elsif @s.star_slash_end? @re.append_many_non_dir dir_only! emit_end elsif @s.two_star_slash_end? dir_only! break! else true end end
process_two_stars()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 94 def process_two_stars # rubocop:disable Metrics/MethodLength return unless @s.two_stars? return break! if @s.end? if @s.slash? if @s.end? @re.append_any_non_dir dir_only! elsif @s.slash? unmatchable_rule! else if nothing_emitted? never_anchored! else emit_any_dir end process_star_end_after_slash end else @re.append_any_non_dir end end
unmatchable_rule!()
click to toggle source
# File lib/path_list/gitignore_rule_builder.rb, line 22 def unmatchable_rule! throw :abort_build, [] end