Sha256: 41c5f760e41c768d2f5b512a0b235656b8a4a5f7a24587a03c2b5051f2ab4df2

Contents?: true

Size: 1.34 KB

Versions: 12

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require_relative 'driver'
require_relative 'utils/string'
module PageMagic
  # class Drivers - creates an object that can be used to hold driver definitions
  # These PageMagic gets the user's chosen driver from this object.
  class Drivers
    def all
      @all ||= []
    end

    # Find a driver definition based on its registered name
    # @param [Symbol] browser registered name of the required browser
    def find(browser)
      all.find { |driver| driver.support?(browser) }
    end

    # Loads drivers defined in files at the given path
    # @param [String] path where the drivers are located
    def load(path = "#{__dir__}/drivers")
      Dir["#{path}/*.rb"].sort.each do |driver_file|
        require driver_file
        driver_name = File.basename(driver_file)[/(.*)\.rb$/, 1]
        register self.class.const_get(Utils::String.classify(driver_name))
      end
    end

    # Make a driver available for selection when creating calling {PageMagic.session}
    # @param [Driver] driver driver definition
    def register(driver)
      all << driver
    end

    # returns true if this driver instance is equal to the supplied object
    # @param [Object] other subject of equality check
    # @return [Boolean] true if the object is a match
    def ==(other)
      other.respond_to?(:all) && all == other.all
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
page_magic-2.0.13 lib/page_magic/drivers.rb
page_magic-2.0.12 lib/page_magic/drivers.rb
page_magic-2.0.11 lib/page_magic/drivers.rb
page_magic-2.0.10 lib/page_magic/drivers.rb
page_magic-2.0.9 lib/page_magic/drivers.rb
page_magic-2.0.6 lib/page_magic/drivers.rb
page_magic-2.0.5 lib/page_magic/drivers.rb
page_magic-2.0.4 lib/page_magic/drivers.rb
page_magic-2.0.3 lib/page_magic/drivers.rb
page_magic-2.0.2 lib/page_magic/drivers.rb
page_magic-2.0.1 lib/page_magic/drivers.rb
page_magic-2.0.0 lib/page_magic/drivers.rb