Class: Docker::API::Collection Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/api/collection.rb

Overview

This class is abstract.

Shared behaviour for the collections hanging off a Client.

Collections are thin by design: each method is one call into the generated operations layer plus whatever wrapping makes the result pleasant. Keeping them thin is what stops the ergonomic layer from drifting away from the API it is supposed to be sugar for.

Direct Known Subclasses

Containers, Images, Networks, System, Volumes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Collection

Returns a new instance of Collection.

Parameters:



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

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientDocker::API::Client (readonly)

Returns the client this collection belongs to.

Returns:



18
19
20
# File 'lib/docker/api/collection.rb', line 18

def client
  @client
end

Instance Method Details

#exist?(id) ⇒ Boolean

Returns whether the object exists.

Parameters:

  • id (String)

    a name or id

Returns:

  • (Boolean)

    whether the object exists



42
43
44
# File 'lib/docker/api/collection.rb', line 42

def exist?(id)
  !find(id).nil?
end

#find(id) ⇒ Docker::API::Resource?

Fetch one object, or nil if the daemon has never heard of it.

The distinction from get is deliberate. Asking for something by a name a user typed is a question; asking for something you just created is an assertion. find answers the question, get makes the assertion and raises when it turns out to be false.

Parameters:

  • id (String)

    a name or id

Returns:



34
35
36
37
38
# File 'lib/docker/api/collection.rb', line 34

def find(id)
  get(id)
rescue NotFound
  nil
end

#to_sString Also known as: inspect

Returns:

  • (String)


47
48
49
# File 'lib/docker/api/collection.rb', line 47

def to_s
  "#<#{self.class.name}>"
end