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
13
# File 'lib/egg/docker_compose.rb', line 10

def initialize(_compose_config = {})
  @services = []
  print "Use of docker_compose is deprecated. Please craft the docker-compose.yml file yourself. This module will be dropped in a future egg."
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:



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

def configure
  yield docker_compose
end

#service(name) ⇒ Object



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

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

#to_yamlObject



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

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