Module: Docker::Model

Included in:
Container, Image
Defined in:
lib/docker/model.rb

Overview

This module is intended to be used as a Mixin for all objects exposed by the Remote API. Currently, these are limited to Containers and Images.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'lib/docker/model.rb', line 4

def connection
  @connection
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/docker/model.rb', line 4

def id
  @id
end

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/docker/model.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#create!(options = {}, excon_options = {}) ⇒ Object

Create a Model with the specified body. Raises A Docker::Error::StateError if the model already exists, and a Docker::Error::ArgumentError if the argument is not a Hash. Otherwise, instances exec the Class’s #create_request method with the single argument.



26
27
28
29
30
31
32
33
34
35
# File 'lib/docker/model.rb', line 26

def create!(options = {}, excon_options = {})
  case
  when self.created?
    raise Docker::Error::StateError, "This #{self.class.name} already exists!"
  when !options.is_a?(Hash)
    raise Docker::Error::ArgumentError, 'Expected a Hash'
  else
    instance_exec(options, excon_options, &self.class.create_request)
  end
end

#created?Boolean

Returns true if the Container has been created, false otherwise.

Returns:



38
39
40
# File 'lib/docker/model.rb', line 38

def created?
  !!self.id
end

#initialize(options = {}) ⇒ Object

Creates a new Model with the specified id and Connection. If a Connection is specified and it is not a Docker::Connection, a Docker::Error::ArgumentError is raised.



13
14
15
16
17
18
19
20
# File 'lib/docker/model.rb', line 13

def initialize(options = {})
  options[:connection] ||= Docker.connection
  unless options[:connection].is_a?(Docker::Connection)
    raise Docker::Error::ArgumentError, "Expected a Docker::Connection."
  end
  self.id = options[:id]
  self.connection = options[:connection]
end

#to_sObject



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

def to_s
  "#{self.class.name} { :id => #{id}, :connection => #{connection} }"
end