Sha256: 8713389b8cbd608dcd9c7d80c19d4ebdcf3654be25197b0c172c1a2328224ae2

Contents?: true

Size: 982 Bytes

Versions: 29

Compression:

Stored size: 982 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 a hash of options that must include an 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"
  # The volumes endpoint returns Name instead of ID, added in the normalize function
  def normalize_hash(hash)
    hash["id"] ||= hash.delete("ID") || hash.delete("Id")
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
docker-api-2.3.0 lib/docker/base.rb
docker-api-2.2.0 lib/docker/base.rb
docker-api-2.1.0 lib/docker/base.rb
docker-api-2.0.0 lib/docker/base.rb
docker-api-2.0.0.pre.1 lib/docker/base.rb
docker-api-1.34.2 lib/docker/base.rb
docker-api-1.34.1 lib/docker/base.rb
docker-api-1.34.0 lib/docker/base.rb
docker-api-1.33.6 lib/docker/base.rb
docker-api-1.33.5 lib/docker/base.rb
docker-api-1.33.4 lib/docker/base.rb
docker-api-1.33.3 lib/docker/base.rb
docker-api-1.33.2 lib/docker/base.rb
docker-api-1.33.1 lib/docker/base.rb
docker-api-1.33.0 lib/docker/base.rb
docker-api-1.32.1 lib/docker/base.rb
docker-api-1.32.0 lib/docker/base.rb
docker-api-1.31.0 lib/docker/base.rb
docker-api-1.30.2 lib/docker/base.rb
docker-api-1.30.1 lib/docker/base.rb