Class: DockerComposeConfig

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

Overview

Support multiple versions for docker-compose configs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ DockerComposeConfig

Returns a new instance of DockerComposeConfig.



5
6
7
# File 'lib/docker_compose_config.rb', line 5

def initialize(filepath)
  parse_docker_compose_config(filepath)
end

Instance Attribute Details

#networksObject (readonly)

Returns the value of attribute networks.



3
4
5
# File 'lib/docker_compose_config.rb', line 3

def networks
  @networks
end

#servicesObject (readonly)

Returns the value of attribute services.



3
4
5
# File 'lib/docker_compose_config.rb', line 3

def services
  @services
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/docker_compose_config.rb', line 3

def version
  @version
end

#volumesObject (readonly)

Returns the value of attribute volumes.



3
4
5
# File 'lib/docker_compose_config.rb', line 3

def volumes
  @volumes
end

Instance Method Details

#parse_docker_compose_config(filepath) ⇒ Object

Parse the docker-compose config



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/docker_compose_config.rb', line 10

def parse_docker_compose_config(filepath)
  config = YAML.load_file(filepath)

  unless config
    config = YAML.load('{}')
  end

  case (config['version'])
  when 2,'2'
    parse_version_2(config)
  else
    parse_version_1(config)
  end
end

#parse_version_1(config) ⇒ Object



32
33
34
35
36
37
# File 'lib/docker_compose_config.rb', line 32

def parse_version_1(config)
  @version = 1
  @services = config
  @volumes = nil
  @networks = nil
end

#parse_version_2(config) ⇒ Object



25
26
27
28
29
30
# File 'lib/docker_compose_config.rb', line 25

def parse_version_2(config)
  @version = 2
  @services = config['services']
  @volumes = config['volumes']
  @networks = config['networks']
end