Class: Docker::Connection

Inherits:
Object
  • Object
show all
Includes:
Error
Defined in:
lib/docker/connection.rb

Overview

This class represents a Connection to a Docker server. The Connection is immutable in that once the url and options is set they cannot be changed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#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
# 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
    @url, @options = url, opts
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/docker/connection.rb', line 6

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/docker/connection.rb', line 6

def url
  @url
end

Instance Method Details

#request(*args, &block) ⇒ Object

Send a request to the server with the ‘



30
31
32
33
34
35
36
37
38
# File 'lib/docker/connection.rb', line 30

def request(*args, &block)
  resource.request(compile_request_params(*args, &block)).body
rescue Excon::Errors::BadRequest => ex
  raise ClientError, ex.message
rescue Excon::Errors::InternalServerError => ex
  raise ServerError, ex.message
rescue Excon::Errors::Timeout => ex
  raise TimeoutError, ex.message
end

#to_sObject



45
46
47
# File 'lib/docker/connection.rb', line 45

def to_s
  "Docker::Connection { :url => #{url}, :options => #{options} }"
end