lib/spidr/settings/proxy.rb in spidr-0.6.1 vs lib/spidr/settings/proxy.rb in spidr-0.7.0

- old
+ new

@@ -1,7 +1,9 @@ require 'spidr/proxy' +require 'uri/http' + module Spidr module Settings # # Methods for configuring a proxy. # @@ -19,11 +21,11 @@ end # # Sets the proxy information used by Agent objects. # - # @param [Spidr::Proxy, Hash, nil] new_proxy + # @param [Spidr::Proxy, Hash, URI::HTTP, String, nil] new_proxy # The new proxy information. # # @option new_proxy [String] :host # The host-name of the proxy. # @@ -39,14 +41,26 @@ # @return [Spidr::Proxy] # The new proxy information. # def proxy=(new_proxy) @proxy = case new_proxy - when Spidr::Proxy then new_proxy - when Hash then Spidr::Proxy.new(new_proxy) - when nil then Spidr::Proxy.new + when Spidr::Proxy + new_proxy + when Hash + Spidr::Proxy.new(**new_proxy) + when String, URI::HTTP + proxy_uri = URI(new_proxy) + + Spidr::Proxy.new( + host: proxy_uri.host, + port: proxy_uri.port, + user: proxy_uri.user, + password: proxy_uri.password + ) + when nil + Spidr::Proxy.new else - raise(TypeError,"#{self.class}#{__method__} only accepts Proxy, Hash or nil") + raise(TypeError,"#{self.class}#{__method__} only accepts Spidr::Proxy, URI::HTTP, Hash, or nil") end end # # Disables the proxy settings used by all newly created Agent objects.