ludwig 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5a2bda97dc8c29beceb35b686578aed84e59a1d
4
- data.tar.gz: 02bcc4b31e7400e314a100f38b50132451e2966d
3
+ metadata.gz: 0b60bb41e36584ba8aac79780e599d4e9bea3249
4
+ data.tar.gz: 8863a356d1a716d4f85fed2b303025ec06cd99ea
5
5
  SHA512:
6
- metadata.gz: 4b9d5f33fab50f542b90a6ff98e5822cf8a73e7775d55aab9b39d4d848af2cb252492d1580fb993f6fbf68061046e0d841050dac24676a5b9032fb800952025f
7
- data.tar.gz: f2d92e30af42c6f9cab36a5aa06af0ee249640ecd043492a0dbea9d6e54bd927d5ee248bb0beb8bba4992b66ad698f2c7c156b3bf1c161e06ff0408e0bac79c1
6
+ metadata.gz: 170c200fdabfcd32cae8d1afa9bb82083f2eb3c03f3cd007b867e2d8e82ec0161b501e9cf326f44f758076cd45877d297cc56818bda0ee6f10c59eba08c17bec
7
+ data.tar.gz: 83224d7dc22c138b0178c683eb5bda14cdd4eea9bc425b377c768c5a0b4a70c90393fcd290aa83c8339c36e2a4f9f40bbeefd520daccd20d1ff393cec6c26170
data/lib/ludwig/cli.rb CHANGED
@@ -3,26 +3,44 @@ require 'yaml'
3
3
  module Ludwig
4
4
  class CLI
5
5
  include Commander::Methods
6
+
6
7
  def run
7
8
  program :version, Ludwig::VERSION
8
9
  program :description, 'Ludwig, the famous composer'
9
10
 
10
- @config = "ludwig.yml"
11
+ @config_file = 'ludwig.yml'
11
12
 
12
13
  global_option('-d', '--debug', 'Enable debug mode') { $debug = true }
13
- global_option('-c', '--config filename', String, 'Set config filename') { |config| @config = config }
14
+ global_option('-c', '--config filename', String, 'Set config filename') { |config_file| @config_file = config_file }
14
15
 
15
16
  command :up do |c|
16
17
  c.syntax = 'ludwig up [options]'
17
18
  c.summary = 'Generate docker-compose.yml and launch docker-compose'
18
19
  c.action do |args, options|
19
- config = YAML.load_file(@config)
20
- composer = Ludwig::Composer.new(config, options)
21
- composer.write_yaml
22
- system("docker-compose up")
20
+ generate_compose_file
21
+ system 'docker-compose up'
22
+ end
23
+ end
24
+
25
+ command :build do |c|
26
+ c.syntax = 'ludwig build [options]'
27
+ c.summary = 'Generate docker-compose.yml'
28
+ c.action do |args, options|
29
+ generate_compose_file
23
30
  end
24
31
  end
32
+
25
33
  run!
26
34
  end
35
+
36
+ private
37
+
38
+ def config
39
+ @config ||= YAML.load_file @config_file
40
+ end
41
+
42
+ def generate_compose_file
43
+ Ludwig::Composer.new(config).write_yaml
44
+ end
27
45
  end
28
46
  end
@@ -1,5 +1,5 @@
1
1
  module Ludwig
2
- class Composer < Struct.new(:config, :options)
2
+ class Composer < Struct.new(:config)
3
3
  def write_yaml
4
4
  File.open('docker-compose.yml','w') do |h|
5
5
  h.write generate_yaml
@@ -14,7 +14,7 @@ module Ludwig
14
14
  config["available_projects"].each_with_object({}) do |project, new_compose_data|
15
15
  data = YAML.load_file("../#{project}/docker-compose.yml")
16
16
  data.each do |service_name, service_data|
17
- service = Service.new(service_name, service_data, project, config)
17
+ service = Service.new(project, service_name, service_data, config)
18
18
  new_compose_data["#{sanitize(project)}_#{service_name}"] = service.generate_yaml
19
19
  end
20
20
  end.to_yaml
@@ -1,22 +1,25 @@
1
1
  module Ludwig
2
- class Service < Struct.new(:name, :data, :project, :config)
2
+ class Service < Struct.new(:project, :name, :data, :config)
3
3
  ACTION_MAP = {
4
- volumes: :volumes_action,
5
- links: :links_action,
4
+ volumes: :volumes_action,
5
+ links: :links_action,
6
6
  env_file: :prefix_path,
7
- build: :prefix_path
7
+ build: :prefix_path
8
8
  }
9
9
 
10
10
  def generate_yaml
11
- data.each_with_object({}) do |(service, service_data), new_data|
12
- new_data[service] = execute_action(service, service_data)
13
- if extra_links = config["extra_links"][service]
14
- extra_links.each do |app|
15
- new_data["links"] ||= []
16
- new_data["links"] << "#{sanitize(app)}_#{config["default_app"]}:#{sanitize(app)}"
17
- end
11
+ new_data = data.each_with_object({}) do |(key, value), memo|
12
+ memo[key] = execute_action(key, value)
13
+ end
14
+
15
+ if extra_links = config["extra_links"][name]
16
+ new_data["links"] ||= []
17
+ new_data["links"] += extra_links.map do |app|
18
+ "#{sanitize(app)}_#{config["default_app"]}:#{sanitize(app)}"
18
19
  end
19
20
  end
21
+
22
+ new_data
20
23
  end
21
24
 
22
25
  def execute_action(key, obj)
@@ -1,3 +1,3 @@
1
1
  module Ludwig
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ludwig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Stolz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander