Class: Docker::API::Collection Abstract
- Inherits:
-
Object
- Object
- Docker::API::Collection
- Defined in:
- lib/docker/api/collection.rb
Overview
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
Instance Attribute Summary collapse
-
#client ⇒ Docker::API::Client
readonly
The client this collection belongs to.
Instance Method Summary collapse
-
#exist?(id) ⇒ Boolean
Whether the object exists.
-
#find(id) ⇒ Docker::API::Resource?
Fetch one object, or nil if the daemon has never heard of it.
-
#initialize(client) ⇒ Collection
constructor
A new instance of Collection.
- #to_s ⇒ String (also: #inspect)
Constructor Details
#initialize(client) ⇒ Collection
Returns a new instance of Collection.
21 22 23 |
# File 'lib/docker/api/collection.rb', line 21 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Docker::API::Client (readonly)
Returns the client this collection belongs to.
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.
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.
34 35 36 37 38 |
# File 'lib/docker/api/collection.rb', line 34 def find(id) get(id) rescue NotFound nil end |
#to_s ⇒ String Also known as: inspect
47 48 49 |
# File 'lib/docker/api/collection.rb', line 47 def to_s "#<#{self.class.name}>" end |