Class: Capybara::Playwright::DialogEventHandler
- Inherits:
-
Object
- Object
- Capybara::Playwright::DialogEventHandler
- Defined in:
- lib/capybara/playwright/dialog_event_handler.rb
Overview
LILO event handler
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#default_handler ⇒ Object
writeonly
Sets the attribute default_handler.
Instance Method Summary collapse
- #add_handler(callable) ⇒ Object
- #handle_dialog(dialog) ⇒ Object
-
#initialize ⇒ DialogEventHandler
constructor
A new instance of DialogEventHandler.
- #remove_handler(id) ⇒ Object
- #with_handler(callable, &block) ⇒ Object
Constructor Details
#initialize ⇒ DialogEventHandler
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
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 |