Class: PathList::GitignoreRuleBuilder
- Inherits:
-
Object
- Object
- PathList::GitignoreRuleBuilder
show all
- Defined in:
- lib/path_list/gitignore_rule_builder.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GitignoreRuleBuilder.
Instance Method Details
#anchored! ⇒ Object
30
31
32
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 30
def anchored!
@anchored ||= true
end
|
#blank! ⇒ Object
18
19
20
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 18
def blank!
throw :abort_build, []
end
|
#break! ⇒ Object
14
15
16
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 14
def break!
throw :break
end
|
#build ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
|
# 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
|
#dir_only! ⇒ Object
38
39
40
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 38
def dir_only!
@dir_only = true
end
|
#emit_any_dir ⇒ Object
51
52
53
54
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 51
def emit_any_dir
anchored!
@re.append_any_dir
end
|
#emit_dir ⇒ Object
46
47
48
49
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 46
def emit_dir
anchored!
@re.append_dir
end
|
#emit_end ⇒ Object
56
57
58
59
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 56
def emit_end
@re.append_end_anchor
break!
end
|
#negated! ⇒ Object
26
27
28
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 26
def negated!
@negation = true
end
|
#never_anchored! ⇒ Object
34
35
36
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 34
def never_anchored!
@anchored = :never
end
|
#nothing_emitted? ⇒ Boolean
42
43
44
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 42
def nothing_emitted?
@re.empty?
end
|
#prefix ⇒ Object
160
161
162
163
164
165
166
167
168
169
|
# 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 ⇒ Object
61
62
63
64
65
|
# 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 ⇒ Object
rubocop:disable Metrics/MethodLength
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 117
def process_character_class 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 ⇒ Object
135
136
137
138
139
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 135
def process_end
blank! if nothing_emitted?
emit_end
end
|
#process_rule ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 141
def process_rule 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 ⇒ Object
85
86
87
88
89
90
91
92
|
# 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 ⇒ Object
rubocop:disable Metrics/MethodLength
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 67
def process_star_end_after_slash 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 ⇒ Object
rubocop:disable Metrics/MethodLength
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 94
def process_two_stars 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! ⇒ Object
22
23
24
|
# File 'lib/path_list/gitignore_rule_builder.rb', line 22
def unmatchable_rule!
throw :abort_build, []
end
|