class TINCheck::Config
Constants
- OPTS
- SERVICE_URI
Attributes
proxy_uri[R]
Public Class Methods
build(&blk)
click to toggle source
# File lib/tincheck/config.rb, line 29 def build(&blk) Config::Builder.(&blk) end
new(**opts)
click to toggle source
# File lib/tincheck/config.rb, line 40 def initialize(**opts) @opts = opts.each_with_object({}) do |(k, v), h| OPTS.include?(k = k.to_sym) && h[k] = v.to_s end defaults! load_xml_lib proxy_uri! end
with_obj(config)
click to toggle source
# File lib/tincheck/config.rb, line 33 def with_obj(config) config.is_a?(self) ? config : new(config) end
Public Instance Methods
opts()
click to toggle source
# File lib/tincheck/config.rb, line 49 def opts @opts.dup end
proxy_args()
click to toggle source
# File lib/tincheck/config.rb, line 53 def proxy_args @proxy_uri ? [@proxy_uri.host, @proxy_uri.port, @proxy_uri.user, @proxy_uri.password] : [] end
with(**opts)
click to toggle source
# File lib/tincheck/config.rb, line 57 def with(**opts) self.class.new(@opts.merge(opts)) end
Private Instance Methods
default_uri(url)
click to toggle source
# File lib/tincheck/config.rb, line 65 def default_uri(url) url ? URI(url) : SERVICE_URI end
default_xml_lib()
click to toggle source
# File lib/tincheck/config.rb, line 69 def default_xml_lib return 'Ox' if defined?(::Ox) return 'Nokogiri' if defined?(::Nokogiri) 'REXML' end
defaults!()
click to toggle source
# File lib/tincheck/config.rb, line 75 def defaults! @opts[:xml_lib] ||= default_xml_lib @opts[:password] ||= ENV['tincheck_password'] @opts[:username] ||= ENV['tincheck_username'] @opts[:uri] ||= default_uri(@opts[:url]) end
load_xml_lib()
click to toggle source
# File lib/tincheck/config.rb, line 82 def load_xml_lib require "tincheck/xml/#{@opts[:xml_lib].downcase}" end
proxy_uri!()
click to toggle source
# File lib/tincheck/config.rb, line 86 def proxy_uri! return unless (url = @opts[:proxy_url] || ENV['HTTP_PROXY'] || ENV['http_proxy']) @proxy_uri = URI(url) end