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- PS_SIZE =
Pattern that parses FIRST occurrence of container size from a string, along with its units.
/^([0-9.]+)\s*([kmgt]?B)/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
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 61 62 63 |
# File 'lib/docker/compose/container.rb', line 23 def initialize(id, image, size, status, names, labels, ports) if size.is_a?(String) && (m = PS_SIZE.match(size)) scalar, units = m[1], m[2] scalar = scalar.to_f # lazy: invalid --> 0.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.
13 14 15 |
# File 'lib/docker/compose/container.rb', line 13 def exitstatus @exitstatus end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/docker/compose/container.rb', line 13 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
13 14 15 |
# File 'lib/docker/compose/container.rb', line 13 def image @image end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
14 15 16 |
# File 'lib/docker/compose/container.rb', line 14 def labels @labels end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
14 15 16 |
# File 'lib/docker/compose/container.rb', line 14 def names @names end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
14 15 16 |
# File 'lib/docker/compose/container.rb', line 14 def ports @ports end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
13 14 15 |
# File 'lib/docker/compose/container.rb', line 13 def size @size end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/docker/compose/container.rb', line 13 def status @status end |
Instance Method Details
#name ⇒ String
71 72 73 |
# File 'lib/docker/compose/container.rb', line 71 def name names.first end |
#up? ⇒ Boolean
76 77 78 |
# File 'lib/docker/compose/container.rb', line 76 def up? self.status == :up end |