Class: PageMagic::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/page_magic/driver.rb

Overview

class Driver - instances are factories for drivers used by PageMagic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*supported_browsers) {|rack_application, options, browser_name| ... } ⇒ Driver

Creates a driver definition @yield[rack_application, options, browser_name]

Examples:

Driver.new do |rack_application, options|
  require 'capybara/driver_class'
  Capybara::Driver::Class.new(app, options)
end

Parameters:

  • supported_browsers (*Symbol)

    list of browsers names. These are the names that you will refer to them by when creating a session

Yield Parameters:

  • rack_application (Object)

    rack compatible application

  • options (Hash)

    hash containing driver specific options

  • browser_name (Symbol)

    the name of the required browser name

Yield Returns:

  • (Object)

    Capybara compliant driver



18
19
20
21
# File 'lib/page_magic/driver.rb', line 18

def initialize(*supported_browsers, &block)
  @handler = block
  @supported_browsers = supported_browsers
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



4
5
6
# File 'lib/page_magic/driver.rb', line 4

def handler
  @handler
end

#supported_browsersObject (readonly)

Returns the value of attribute supported_browsers.



4
5
6
# File 'lib/page_magic/driver.rb', line 4

def supported_browsers
  @supported_browsers
end

Instance Method Details

#build(app, browser:, options: {}) ⇒ Object

Build a new driver instance based on this definition

Parameters:

  • app (Object)
    • rack compatible application
  • browser (Symbol)

    name of required browser

  • options (Hash) (defaults to: {})

    driver specific options

Returns:

  • (Object)

    Capybara compliant driver instance



28
29
30
# File 'lib/page_magic/driver.rb', line 28

def build(app, browser:, options: {})
  handler.call(app, options, browser)
end

#support?(browser) ⇒ Boolean

Determines if the given browser name is supported by this driver definition

Parameters:

  • browser (Symbol)

    name of browser

Returns:

  • (Boolean)

    true if definition supports the given driver name



35
36
37
# File 'lib/page_magic/driver.rb', line 35

def support?(browser)
  supported_browsers.include?(browser)
end