Class: Playwright::RouteHandler
- Inherits:
-
Object
- Object
- Playwright::RouteHandler
show all
- Defined in:
- lib/playwright/route_handler.rb
Defined Under Namespace
Classes: CountDown, StubCounter
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url, base_url, handler, times) ⇒ RouteHandler
Returns a new instance of RouteHandler.
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/playwright/route_handler.rb', line 34
def initialize(url, base_url, handler, times)
@url_value = url
@url_matcher = UrlMatcher.new(url, base_url: base_url)
@handler = handler
@counter =
if times
CountDown.new(times)
else
StubCounter.new
end
end
|
Class Method Details
.prepare_interception_patterns(handlers) ⇒ Object
74
75
76
|
# File 'lib/playwright/route_handler.rb', line 74
def self.prepare_interception_patterns(handlers)
handlers.map(&:as_pattern).compact
end
|
Instance Method Details
#as_pattern ⇒ Object
46
47
48
|
# File 'lib/playwright/route_handler.rb', line 46
def as_pattern
@url_matcher.as_pattern
end
|
#async_handle(route) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/playwright/route_handler.rb', line 54
def async_handle(route)
@counter.increment
Concurrent::Promises.future { @handler.call(route, route.request) }.rescue do |err|
puts err, err.backtrace
end
end
|
#expired? ⇒ Boolean
62
63
64
|
# File 'lib/playwright/route_handler.rb', line 62
def expired?
@counter.expired?
end
|
#match?(url) ⇒ Boolean
50
51
52
|
# File 'lib/playwright/route_handler.rb', line 50
def match?(url)
@url_matcher.match?(url)
end
|
#same_value?(url:, handler: nil) ⇒ Boolean
66
67
68
69
70
71
72
|
# File 'lib/playwright/route_handler.rb', line 66
def same_value?(url:, handler: nil)
if handler
@url_value == url && @handler == handler
else
@url_value == url
end
end
|