Class: Docker::Compose::Container
- Inherits:
-
Object
- Object
- Docker::Compose::Container
- Defined in:
- lib/docker/compose/container.rb
Constant Summary collapse
- PS_FMT =
Format string for ‘docker ps`
'({{.ID}}) ({{.Image}}) ({{.Size}}) ({{.Status}}) ({{.Names}}) ({{.Labels}}) ({{.Ports}})'
- PS_FMT_LEN =
Number of template substitutions in PS_FMT
PS_FMT.count('.')
- PS_STATUS =
Pattern that parses human-readable values from ps .Status
/^([A-Za-z]+) ?\(?([0-9]*)\)? ?(.*)$/i
Instance Attribute Summary collapse
-
#exitstatus ⇒ Object
readonly
Returns the value of attribute exitstatus.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(id, image, size, status, names, labels, ports) ⇒ Container
constructor
A new instance of Container.
- #name ⇒ String
- #up? ⇒ Boolean
Constructor Details
#initialize(id, image, size, status, names, labels, ports) ⇒ Container
Returns a new instance of Container.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/docker/compose/container.rb', line 20 def initialize(id, image, size, status, names, labels, ports) if size.is_a?(String) scalar, units = size.split(' ') scalar = size[0].to_i # lazy: invalid --> 0 mult = case units.downcase when 'b' then 1 when 'kb' then 1_024 when 'mb' then 1_024^2 when 'gb' then 1_024^3 when 'tb' then 1_024^4 else raise Error.new('Service#new', units, 'Impossibly large unit') end size = scalar * mult end if status.is_a?(String) status = PS_STATUS.match(status) raise Error.new('Service#new', status, 'Unrecognized status') unless status end names = names.split(',').map{ |x| x.strip } if names.is_a?(String) labels = labels.split(',').map{ |x| x.strip } if labels.is_a?(String) ports = ports.split(',').map{ |x| x.strip } if ports.is_a?(String) @id = id @image = image @size = size @status = status[1].downcase.to_sym @exitstatus = case @status when :up nil else status[2].to_i end @names = names @labels = labels @ports = ports end |
Instance Attribute Details
#exitstatus ⇒ Object (readonly)
Returns the value of attribute exitstatus.
10 11 12 |
# File 'lib/docker/compose/container.rb', line 10 def exitstatus @exitstatus end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/docker/compose/container.rb', line 10 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
10 11 12 |
# File 'lib/docker/compose/container.rb', line 10 def image @image end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
11 12 13 |
# File 'lib/docker/compose/container.rb', line 11 def labels @labels end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
11 12 13 |
# File 'lib/docker/compose/container.rb', line 11 def names @names end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
11 12 13 |
# File 'lib/docker/compose/container.rb', line 11 def ports @ports end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
10 11 12 |
# File 'lib/docker/compose/container.rb', line 10 def size @size end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/docker/compose/container.rb', line 10 def status @status end |
Instance Method Details
#name ⇒ String
68 69 70 |
# File 'lib/docker/compose/container.rb', line 68 def name names.first end |
#up? ⇒ Boolean
73 74 75 |
# File 'lib/docker/compose/container.rb', line 73 def up? self.status == :up end |