lib/percheron/docker_connection.rb in percheron-0.2.0 vs lib/percheron/docker_connection.rb in percheron-0.2.1

- old
+ new

@@ -4,40 +4,50 @@ def initialize(config) @config = config end def setup! - Docker.logger = $logger if ENV['DOCKER_DEBUG'] == 'true' - Docker.url = config.docker.host - - opts = { - chunk_size: 1, - connect_timeout: config.docker.timeout, - scheme: 'https' - } - - if cert_path - opts.merge!({ - client_cert: File.join(cert_path, 'cert.pem'), - client_key: File.join(cert_path, 'key.pem'), - ssl_ca_file: File.join(cert_path, 'ca.pem') - }) - end - - Docker.options = opts + set_url! + set_options! end private attr_reader :config def cert_path - @cert_path ||= begin - if ENV['DOCKER_CERT_PATH'] - File.expand_path(ENV['DOCKER_CERT_PATH']) - else - nil - end + @cert_path ||= ENV['DOCKER_CERT_PATH'] ? File.expand_path(ENV['DOCKER_CERT_PATH']) : nil + end + + def set_url! + Docker.url = config.docker.host + end + + def set_options! + Docker.options = docker_options + end + + def docker_options + base_docker_options.merge(extra_docker_opts) + end + + def base_docker_options + { + connect_timeout: config.docker.timeout, + scheme: 'https' + } + end + + def extra_docker_opts + if cert_path + { + client_cert: File.join(cert_path, 'cert.pem'), + client_key: File.join(cert_path, 'key.pem'), + ssl_ca_file: File.join(cert_path, 'ca.pem') + } + else + {} end end + end end