Class: Playwright::RouteHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/playwright/route_handler.rb

Defined Under Namespace

Classes: CountDown, StubCounter

Instance Method Summary collapse

Constructor Details

#initialize(url, base_url, handler, times) ⇒ 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

Instance Method Details

#async_handle(route, request) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/playwright/route_handler.rb', line 50

def async_handle(route, request)
  @counter.increment

  Concurrent::Promises.future do
    @handler.call(route, request)
  rescue => err
    puts err, err.backtrace
  end
end

#expired?Boolean



60
61
62
# File 'lib/playwright/route_handler.rb', line 60

def expired?
  @counter.expired?
end

#match?(url) ⇒ Boolean



46
47
48
# File 'lib/playwright/route_handler.rb', line 46

def match?(url)
  @url_matcher.match?(url)
end

#same_value?(url:, handler: nil) ⇒ Boolean



64
65
66
67
68
69
70
# File 'lib/playwright/route_handler.rb', line 64

def same_value?(url:, handler: nil)
  if handler
    @url_value == url && @handler == handler
  else
    @url_value == url
  end
end