Method: Docker::Compose::Container#initialize
- Defined in:
- lib/docker/compose/container.rb
#initialize(id, image, size, status, names, labels, ports) ⇒ Container
Returns a new instance of 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 |