Method: Docker::Connection#initialize

Defined in:
lib/docker/connection.rb

#initialize(url, opts) ⇒ Connection

Create a new Connection. This method takes a url (String) and options (Hash). These are passed to Excon, so any options valid for ‘Excon.new` can be passed here.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/docker/connection.rb', line 11

def initialize(url, opts)
  case
  when !url.is_a?(String)
    raise ArgumentError, "Expected a String, got: '#{url}'"
  when !opts.is_a?(Hash)
    raise ArgumentError, "Expected a Hash, got: '#{opts}'"
  else
    uri = URI.parse(url)
    if uri.scheme == "unix"
      @url, @options = 'unix:///', {:socket => uri.path}.merge(opts)
    elsif uri.scheme =~ /^(https?|tcp)$/
      @url, @options = url, opts
    else
      @url, @options = "http://#{uri}", opts
    end
  end
end