Class: DockerComposeConfig
- Inherits:
-
Object
- Object
- DockerComposeConfig
- Defined in:
- lib/docker_compose_config.rb
Overview
Support multiple versions for docker-compose configs.
Instance Attribute Summary collapse
-
#networks ⇒ Object
readonly
Returns the value of attribute networks.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#volumes ⇒ Object
readonly
Returns the value of attribute volumes.
Instance Method Summary collapse
-
#initialize(filepath) ⇒ DockerComposeConfig
constructor
A new instance of DockerComposeConfig.
-
#parse_docker_compose_config(filepath) ⇒ Object
Parse the docker-compose config.
- #parse_version_1(config) ⇒ Object
- #parse_version_2(config) ⇒ Object
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
#networks ⇒ Object (readonly)
Returns the value of attribute networks.
3 4 5 |
# File 'lib/docker_compose_config.rb', line 3 def networks @networks end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
3 4 5 |
# File 'lib/docker_compose_config.rb', line 3 def services @services end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/docker_compose_config.rb', line 3 def version @version end |
#volumes ⇒ Object (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 24 25 26 |
# File 'lib/docker_compose_config.rb', line 10 def parse_docker_compose_config(filepath) f = File.read(filepath) f = f.gsub(/\$([a-zA-Z_]+[a-zA-Z0-9_]*)|\$\{(.+)\}/) { ENV[$1 || $2] } config = YAML.load(f) 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
35 36 37 38 39 40 |
# File 'lib/docker_compose_config.rb', line 35 def parse_version_1(config) @version = 1 @services = config @volumes = nil @networks = nil end |
#parse_version_2(config) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/docker_compose_config.rb', line 28 def parse_version_2(config) @version = 2 @services = config['services'] @volumes = config['volumes'] @networks = config['networks'] end |