class Playwright::PlaywrightApi::ChannelOwnerWrapper

Public Class Methods

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

  @impl = impl
end

Public Instance Methods

wrap() click to toggle source
# File lib/playwright/playwright_api.rb, line 42
def wrap
  api_class = detect_class_for(@impl.class)
  if api_class
    @impl._api ||= 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 61
def detect_class_for(klass)
  class_name = expected_class_name_for(klass)
  if ::Playwright.const_defined?(class_name)
    ::Playwright.const_get(class_name)
  elsif superclass_exist?(klass)
    detect_class_for(klass.superclass)
  else
    nil
  end
end
expected_class_name_for(klass) click to toggle source
# File lib/playwright/playwright_api.rb, line 53
def expected_class_name_for(klass)
  klass.name.split("::ChannelOwners::").last
end
superclass_exist?(klass) click to toggle source
# File lib/playwright/playwright_api.rb, line 57
def superclass_exist?(klass)
  ![::Playwright::ChannelOwner, Object].include?(klass.superclass)
end