Class: FastIgnore::PathRegexpBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_ignore/path_regexp_builder.rb

Instance Method Summary collapse

Constructor Details

#initializePathRegexpBuilder

Returns a new instance of PathRegexpBuilder.



5
6
7
# File 'lib/fast_ignore/path_regexp_builder.rb', line 5

def initialize
  @string = +''
end

Instance Method Details

#append(value) ⇒ Object Also known as: <<



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fast_ignore/path_regexp_builder.rb', line 37

def append(value)
  @string.<<(value)

  self
rescue FrozenError
  # :nocov:
  # the string seems to become inadvertently frozen in 2.5 and 2.6 with specific inputs
  # and i don't understand why
  # it seems like it's happening during the Regexp.new
  # for some reason that i don't understand
  @string = @string.dup
  append(value)
  # :nocov:
end

#append_any_dirObject



80
81
82
# File 'lib/fast_ignore/path_regexp_builder.rb', line 80

def append_any_dir
  append('(?:.*/)?')
end

#append_any_non_dirObject



88
89
90
91
# File 'lib/fast_ignore/path_regexp_builder.rb', line 88

def append_any_non_dir
  append_one_non_dir
  append('*')
end

#append_character_class_closeObject



126
127
128
# File 'lib/fast_ignore/path_regexp_builder.rb', line 126

def append_character_class_close
  append(']')
end

#append_character_class_dashObject



122
123
124
# File 'lib/fast_ignore/path_regexp_builder.rb', line 122

def append_character_class_dash
  append('-')
end

#append_character_class_negationObject



118
119
120
# File 'lib/fast_ignore/path_regexp_builder.rb', line 118

def append_character_class_negation
  append('^')
end

#append_character_class_openObject



114
115
116
# File 'lib/fast_ignore/path_regexp_builder.rb', line 114

def append_character_class_open
  append('(?!/)[')
end

#append_dirObject



76
77
78
# File 'lib/fast_ignore/path_regexp_builder.rb', line 76

def append_dir
  append('/')
end

#append_dir_or_end_anchorObject



110
111
112
# File 'lib/fast_ignore/path_regexp_builder.rb', line 110

def append_dir_or_end_anchor
  append('(?:/|\\z)')
end

#append_dir_or_start_anchorObject



106
107
108
# File 'lib/fast_ignore/path_regexp_builder.rb', line 106

def append_dir_or_start_anchor
  append('(?:\\A|/)')
end

#append_end_anchorObject



98
99
100
# File 'lib/fast_ignore/path_regexp_builder.rb', line 98

def append_end_anchor
  append('\\z')
end

#append_escaped(value) ⇒ Object

builder methods



70
71
72
73
74
# File 'lib/fast_ignore/path_regexp_builder.rb', line 70

def append_escaped(value)
  return unless value

  append(::Regexp.escape(value))
end

#append_many_non_dirObject



93
94
95
96
# File 'lib/fast_ignore/path_regexp_builder.rb', line 93

def append_many_non_dir
  append_one_non_dir
  append('+')
end

#append_one_non_dirObject



84
85
86
# File 'lib/fast_ignore/path_regexp_builder.rb', line 84

def append_one_non_dir
  append('[^/]')
end

#append_start_anchorObject



102
103
104
# File 'lib/fast_ignore/path_regexp_builder.rb', line 102

def append_start_anchor
  append('\\A')
end

#dupObject

String methods



16
17
18
19
20
21
22
# File 'lib/fast_ignore/path_regexp_builder.rb', line 16

def dup
  out = super

  @string = @string.dup

  out
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fast_ignore/path_regexp_builder.rb', line 29

def empty?
  @string.empty?
end

#end_with?(str) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/fast_ignore/path_regexp_builder.rb', line 33

def end_with?(str)
  @string.end_with?(str)
end

#prepend(value) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fast_ignore/path_regexp_builder.rb', line 53

def prepend(value)
  @string.prepend(value)

  self
rescue FrozenError
  # :nocov:
  # the string seems to become inadvertently frozen in 2.5 and 2.6 with specific inputs
  # and i don't understand why
  # it seems like it's happening during the Regexp.new
  # for some reason that i don't understand
  @string = @string.dup
  prepend(value)
  # :nocov:
end

#to_regexpObject



9
10
11
12
# File 'lib/fast_ignore/path_regexp_builder.rb', line 9

def to_regexp
  # Regexp::IGNORECASE = 1
  ::Regexp.new(@string, 1)
end

#to_strObject Also known as: to_s



24
25
26
# File 'lib/fast_ignore/path_regexp_builder.rb', line 24

def to_str
  @string
end