Module: Orchparty::Plugin::DockerComposeV2
- Defined in:
- lib/orchparty/plugins/docker_compose_v2.rb
Class Method Summary collapse
- .define_flags(c) ⇒ Object
- .desc ⇒ Object
- .generate(ast, options) ⇒ Object
- .output(application) ⇒ Object
- .transform_to_yaml(hash) ⇒ Object
Class Method Details
.define_flags(c) ⇒ Object
10 11 12 |
# File 'lib/orchparty/plugins/docker_compose_v2.rb', line 10 def self.define_flags(c) c.flag [:output,:o], :desc => 'Set the output file' end |
.desc ⇒ Object
6 7 8 |
# File 'lib/orchparty/plugins/docker_compose_v2.rb', line 6 def self.desc "generate docker-compose v2 file" end |
.generate(ast, options) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/orchparty/plugins/docker_compose_v2.rb', line 14 def self.generate(ast, ) output = output(ast) if [:output] File.write([:output], output) else puts output end end |
.output(application) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/orchparty/plugins/docker_compose_v2.rb', line 28 def self.output(application) output_hash = {"version" => "2", "services" => application.services.map do |name,service| service = service.to_h [service.delete(:name), HashUtils.deep_stringify_keys(service.to_h)] end.to_h, } output_hash["volumes"] = transform_to_yaml(application.volumes) if application.volumes && !application.volumes.empty? output_hash["networks"] = transform_to_yaml(application.networks) if application.networks && !application.networks.empty? output_hash.to_yaml(line_width: -1) end |
.transform_to_yaml(hash) ⇒ Object
23 24 25 26 |
# File 'lib/orchparty/plugins/docker_compose_v2.rb', line 23 def self.transform_to_yaml(hash) hash = hash.deep_transform_values{|v| v.is_a?(Hash) ? v.to_h : v } HashUtils.deep_stringify_keys(hash) end |