Sha256: 805c12f3531526c9d4d3884f83e2f22cf181170840aab29137a1990165ff29ad

Contents?: true

Size: 867 Bytes

Versions: 36

Compression:

Stored size: 867 Bytes

Contents

# This class is a base class for Docker Container and Image.
# It is implementing accessor methods for the models attributes.
module Docker::Base
  include Docker::Error

  attr_accessor :connection, :info
  attr_reader :id

  # The private new method accepts a connection and optional id.
  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

  # 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"
  def normalize_hash(hash)
    hash["id"] ||= hash.delete("ID") || hash.delete("Id")
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
docker-api-1.21.4 lib/docker/base.rb
docker-api-1.21.3 lib/docker/base.rb
docker-api-1.21.2 lib/docker/base.rb
docker-api-1.21.1 lib/docker/base.rb
docker-api-1.21.0 lib/docker/base.rb
docker-api-1.20.0 lib/docker/base.rb
docker-api-1.19.0 lib/docker/base.rb
docker-api-1.18.0 lib/docker/base.rb
docker-api-1.17.0 lib/docker/base.rb
docker-api-1.16.1 lib/docker/base.rb
docker-api-1.16.0 lib/docker/base.rb
docker-api-1.15.0 lib/docker/base.rb
docker-api-1.14.0 lib/docker/base.rb
docker-api-1.13.7 lib/docker/base.rb
docker-api-1.13.6 lib/docker/base.rb
docker-api-1.13.5 lib/docker/base.rb
docker-api-1.13.4 lib/docker/base.rb
docker-api-1.13.3 lib/docker/base.rb
docker-api-1.13.2 lib/docker/base.rb
docker-api-1.13.1 lib/docker/base.rb