Class: Docker::Base

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

Overview

This class is a base class for Docker Container and Image. It is implementing accessor methods for the models attributes.

Direct Known Subclasses

Container, Image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, hash = {}) ⇒ Base

The private new method accepts a connection and optional id.

Raises:



10
11
12
13
14
15
16
17
# File 'lib/docker/base.rb', line 10

def initialize(connection, hash={})
  unless connection.is_a?(Docker::Connection)
    raise ArgumentError, "Expected a Docker::Connection, got: #{connection}."
  end
  normalize_hash(hash)
  @connection, @info, @id = connection, hash, hash['id']
  raise ArgumentError, "Must have id, got: #{hash}" unless @id
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/docker/base.rb', line 7

def id
  @id
end

#infoObject

Returns the value of attribute info.



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

def info
  @info
end

Instance Method Details

#normalize_hash(hash) ⇒ Object

The docker-api will some time return “ID” other times it will return “Id” and other times it will return “id”. This method normalize it to “id”



21
22
23
# File 'lib/docker/base.rb', line 21

def normalize_hash(hash)
  hash["id"] ||= hash.delete("ID") || hash.delete("Id")
end