class Playwright::PlaywrightApi::ApiImplementationWrapper

Public Class Methods

new(impl) click to toggle source
# File lib/playwright/playwright_api.rb, line 74
def initialize(impl)
  impl_class_name = impl.class.name
  unless impl_class_name.end_with?("Impl")
    raise "#{impl_class_name} is not Impl"
  end

  @impl = impl
end

Public Instance Methods

wrap() click to toggle source
# File lib/playwright/playwright_api.rb, line 83
def wrap
  api_class = detect_class_for(@impl.class)
  if api_class
    api_class.new(@impl)
  else
    raise NotImplementedError.new("Playwright::#{expected_class_name_for(@impl.class)} is not implemented")
  end
end

Private Instance Methods

detect_class_for(klass) click to toggle source
# File lib/playwright/playwright_api.rb, line 100
def detect_class_for(klass)
  class_name = expected_class_name_for(klass)
  if ::Playwright.const_defined?(class_name)
    ::Playwright.const_get(class_name)
  else
    nil
  end
end
expected_class_name_for(klass) click to toggle source
# File lib/playwright/playwright_api.rb, line 94
def expected_class_name_for(klass)
  # KeyboardImpl -> Keyboard
  # MouseImpl -> Mouse
  klass.name[0...-4].split("::").last
end