Class: DockerCompose

Inherits:
Object
  • Object
show all
Defined in:
lib/egg/docker_compose.rb,
lib/egg/docker_compose/service.rb

Overview

Wraps the generation of Docker Compose file

Defined Under Namespace

Classes: Service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_compose_config = {}) ⇒ DockerCompose

Returns a new instance of DockerCompose.



10
11
12
# File 'lib/egg/docker_compose.rb', line 10

def initialize(_compose_config = {})
  @services = []
end

Instance Attribute Details

#docker_composeObject (readonly)

Returns the value of attribute docker_compose.



7
8
9
# File 'lib/egg/docker_compose.rb', line 7

def docker_compose
  @docker_compose
end

#servicesObject (readonly)

Returns the value of attribute services.



7
8
9
# File 'lib/egg/docker_compose.rb', line 7

def services
  @services
end

Instance Method Details

#configure {|docker_compose| ... } ⇒ Object

Yields:



14
15
16
# File 'lib/egg/docker_compose.rb', line 14

def configure
  yield docker_compose
end

#service(name) ⇒ Object



27
28
29
30
31
# File 'lib/egg/docker_compose.rb', line 27

def service(name)
  service = Service.new(name)
  services << service
  service
end

#to_yamlObject



18
19
20
21
22
23
24
25
# File 'lib/egg/docker_compose.rb', line 18

def to_yaml
  output = { "version" => "2" }
  output["services"] = services.each_with_object({}) do |service, hash|
    hash[service.name] = service.to_hash
  end

  output.to_yaml
end