Sha256: a09eb8309563eb8cc880df6248ab3fc1a119174feacfa5992d1a463e97bf0962

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

module ProxyFetcher
  class Configuration
    UnknownProvider = Class.new(StandardError)
    RegisteredProvider = Class.new(StandardError)

    attr_accessor :open_timeout, :read_timeout, :provider
    attr_accessor :http_client

    class << self
      def providers
        @providers ||= {}
      end

      def register_provider(name, klass)
        raise RegisteredProvider, "#{name} provider already registered!" if providers.key?(name.to_sym)

        providers[name.to_sym] = klass
      end
    end

    def initialize
      @open_timeout = 3
      @read_timeout = 3
      @http_client = HTTPClient

      self.provider = :hide_my_name # currently default one
    end

    def provider=(name)
      @provider = self.class.providers[name.to_sym]

      raise UnknownProvider, "unregistered proxy provider (#{name})!" if @provider.nil?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
proxy_fetcher-0.2.5 lib/proxy_fetcher/configuration.rb