Class: DC::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/dc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, directory:) ⇒ Group

Returns a new instance of Group.



97
98
99
100
101
102
# File 'lib/dc.rb', line 97

def initialize hash, directory:
  @hash = hash
  @images = hash.keys.map do |name|
    Image.new name, directory: "#{directory}/#{name}"
  end
end

Instance Attribute Details

#imagesObject (readonly)

Returns the value of attribute images.



104
105
106
# File 'lib/dc.rb', line 104

def images
  @images
end

Instance Method Details

#build_missing_imagesObject



110
111
112
113
114
# File 'lib/dc.rb', line 110

def build_missing_images
  @images.each do |image|
    image.build unless image.exist?
  end
end

#containersObject



106
107
108
# File 'lib/dc.rb', line 106

def containers
  @containers ||= create_containers
end

#rebuild_imagesObject



126
127
128
129
130
131
# File 'lib/dc.rb', line 126

def rebuild_images
  images.each do |image|
    image.tag "before_rebuild.#{Time.now.to_i}"
    image.build
  end
end

#startObject



116
117
118
119
120
# File 'lib/dc.rb', line 116

def start
  network = Network.new
  containers.each { |container| network.connect container.id }
  containers.each &:start
end

#stopObject



122
123
124
# File 'lib/dc.rb', line 122

def stop
  containers.each &:destroy
end