Class: Capybara::Playwright::DialogEventHandler

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

Overview

LILO event handler

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDialogEventHandler

Returns a new instance of DialogEventHandler.



20
21
22
23
# File 'lib/capybara/playwright/dialog_event_handler.rb', line 20

def initialize
  @handlers = []
  @mutex = Mutex.new
end

Instance Attribute Details

#default_handler=(value) ⇒ Object (writeonly)

Sets the attribute default_handler

Parameters:

  • value

    the value to set the attribute default_handler to.



25
26
27
# File 'lib/capybara/playwright/dialog_event_handler.rb', line 25

def default_handler=(value)
  @default_handler = value
end

Instance Method Details

#add_handler(callable) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/capybara/playwright/dialog_event_handler.rb', line 27

def add_handler(callable)
  item = Item.new(callable)
  @mutex.synchronize {
    @handlers << item
  }
  item.id
end

#handle_dialog(dialog) ⇒ Object



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

def handle_dialog(dialog)
  handler = @mutex.synchronize {
    @handlers.pop || @default_handler
  }
  handler&.call(dialog)
end

#remove_handler(id) ⇒ Object



35
36
37
38
39
# File 'lib/capybara/playwright/dialog_event_handler.rb', line 35

def remove_handler(id)
  @mutex.synchronize {
    @handlers.reject! { |item| item.id == id }
  }
end

#with_handler(callable, &block) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/capybara/playwright/dialog_event_handler.rb', line 41

def with_handler(callable, &block)
  id = add_handler(callable)
  begin
    block.call
  ensure
    remove_handler(id)
  end
end