Sha256: 382377d0a9eb9e581e35e96f69a04697fe3bf54bd28010e3f3b491bf6b7d1ff4

Contents?: true

Size: 887 Bytes

Versions: 1

Compression:

Stored size: 887 Bytes

Contents

require 'page_magic/driver'
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

    def register(driver)
      all << driver
    end

    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")
      require 'active_support/inflector'

      Dir["#{path}/*.rb"].each do |driver_file|
        require driver_file
        driver_name = File.basename(driver_file)[/(.*)\.rb$/, 1]
        register self.class.const_get(driver_name.classify)
      end
    end

    def ==(other)
      other.is_a?(Drivers) && all == other.all
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
page_magic-1.0.0.alpha18 lib/page_magic/drivers.rb