@@ -213,38 +213,50 @@ def build_exchange(id)
213
213
214
214
private
215
215
216
- def everylist_subscribe
217
- @_everylist_subscribed ||= begin
218
- return if Array ( @ whitelist) . none? && Array ( @blacklist ) . none ?
216
+ def blacklist_subscribe
217
+ return unless blacklist?
218
+ raise ArgumentError , "You can't use blacklist along with whitelist" if whitelist ?
219
219
220
+ @blacklist_subscribe ||= begin
220
221
intercept
221
222
222
- @page . on ( :request ) do |request , index , total |
223
- if @blacklist &.any?
224
- if @blacklist . any? { |pattern | request . match? ( pattern ) }
225
- request . abort and next
226
- else
227
- request . continue and next
228
- end
229
- elsif @whitelist &.any?
230
- if @whitelist . any? { |pattern | request . match? ( pattern ) }
231
- request . continue and next
232
- else
233
- request . abort and next
234
- end
235
- elsif index + 1 < total
236
- # There are other callbacks that may handle this request
237
- next
223
+ @page . on ( :request ) do |request |
224
+ if @blacklist . any? { |p | request . match? ( p ) }
225
+ request . abort
238
226
else
239
- # If there are no callbacks then just continue
240
227
request . continue
241
228
end
242
229
end
243
230
244
231
true
245
232
end
246
233
end
247
- alias whitelist_subscribe everylist_subscribe
248
- alias blacklist_subscribe everylist_subscribe
234
+
235
+ def whitelist_subscribe
236
+ return unless whitelist?
237
+ raise ArgumentError , "You can't use whitelist along with blacklist" if blacklist?
238
+
239
+ @whitelist_subscribe ||= begin
240
+ intercept
241
+
242
+ @page . on ( :request ) do |request |
243
+ if @whitelist . any? { |p | request . match? ( p ) }
244
+ request . continue
245
+ else
246
+ request . abort
247
+ end
248
+ end
249
+
250
+ true
251
+ end
252
+ end
253
+
254
+ def blacklist?
255
+ Array ( @blacklist ) . any?
256
+ end
257
+
258
+ def whitelist?
259
+ Array ( @whitelist ) . any?
260
+ end
249
261
end
250
262
end
0 commit comments