Module: Docker::Base
Overview
This class is a base class for Docker Container and Image. It is implementing accessor methods for the models attributes.
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#info ⇒ Object
Returns the value of attribute info.
Instance Method Summary collapse
-
#initialize(connection, hash = {}) ⇒ Object
The private new method accepts a connection and a hash of options that must include an id.
-
#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”.
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
8 9 10 |
# File 'lib/docker/base.rb', line 8 def connection @connection end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/docker/base.rb', line 9 def id @id end |
#info ⇒ Object
Returns the value of attribute info.
8 9 10 |
# File 'lib/docker/base.rb', line 8 def info @info end |
Instance Method Details
#initialize(connection, hash = {}) ⇒ Object
The private new method accepts a connection and a hash of options that must include an id.
12 13 14 15 16 17 18 19 |
# File 'lib/docker/base.rb', line 12 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 |
#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” The volumes endpoint returns Name instead of ID, added in the normalize function
24 25 26 |
# File 'lib/docker/base.rb', line 24 def normalize_hash(hash) hash["id"] ||= hash.delete("ID") || hash.delete("Id") end |