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

#expired?Boolean

Returns:

  • (Boolean)


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

def expired?
  @counter.expired?
end

#handle(route, request) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/playwright/route_handler.rb', line 46

def handle(route, request)
  return false unless @counter.handle

  if @url_matcher.match?(request.url)
    @handler.call(route, request)
    true
  else
    false
  end
end

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

Returns:

  • (Boolean)


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

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