Module: Docker::Model
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
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#create!(options = {}, excon_options = {}) ⇒ Object
Create a Model with the specified body.
-
#created? ⇒ Boolean
Returns true if the Container has been created, false otherwise.
-
#initialize(options = {}) ⇒ Object
Creates a new Model with the specified id and Connection.
- #to_s ⇒ Object
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
4 5 6 |
# File 'lib/docker/model.rb', line 4 def connection @connection end |
#id ⇒ Object
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!( = {}, = {}) case when self.created? raise Docker::Error::StateError, "This #{self.class.name} already exists!" when !.is_a?(Hash) raise Docker::Error::ArgumentError, 'Expected a Hash' else instance_exec(, , &self.class.create_request) end end |
#created? ⇒ Boolean
Returns true if the Container has been created, false otherwise.
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( = {}) [:connection] ||= Docker.connection unless [:connection].is_a?(Docker::Connection) raise Docker::Error::ArgumentError, "Expected a Docker::Connection." end self.id = [:id] self.connection = [:connection] end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/docker/model.rb', line 42 def to_s "#{self.class.name} { :id => #{id}, :connection => #{connection} }" end |