lib/hoosegow/docker.rb in hoosegow-1.2.1 vs lib/hoosegow/docker.rb in hoosegow-1.2.2

- old
+ new

@@ -36,11 +36,11 @@ # } # `:volumes => { "/work" => "/home/localuser/work/to/do" }` # :Other - any option with a capitalized key will be passed on # to the 'create container' call. See http://docs.docker.io/en/latest/reference/api/docker_remote_api_v1.9/#create-a-container def initialize(options = {}) - ::Docker.url = docker_url options + set_docker_url! options @after_create = options[:after_create] @after_start = options[:after_start] @after_stop = options[:after_stop] @volumes = options[:volumes] @prestart = options.fetch(:prestart, true) @@ -166,10 +166,17 @@ def image_exist?(name) ::Docker::Image.exist? name end private + # Private: Set the docker URL, if related options are present. + def set_docker_url!(options) + if url = docker_url(options) + ::Docker.url = url + end + end + # Private: Get the URL to use for communicating with Docker. If a host and/or # port a present, a TCP socket URL will be generated. Otherwise a Unix # socket will be used. # # options - A Hash of options for building the URL. @@ -182,12 +189,13 @@ def docker_url(options) if options[:host] || options[:port] host = options[:host] || DEFAULT_HOST port = options[:port] || DEFAULT_PORT "tcp://#{host}:#{port}" - else - path = options[:socket] || DEFAULT_SOCKET + elsif path = options[:socket] "unix://#{path}" + else + nil end end # Private: Generate the `Volumes` argument for creating a container. #