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

Returns a new instance of RouteHandler.

Parameters:

  • url (String)
  • base_url (String|nil)
  • handler (Proc)
  • times (Integer|nil)


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) ⇒ Object



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

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

Returns:

  • (Boolean)


58
59
60
# File 'lib/playwright/route_handler.rb', line 58

def expired?
  @counter.expired?
end

#match?(url) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

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