Class: CF::Deploy::EnvConfig
- Inherits:
-
Hash
- Object
- Hash
- CF::Deploy::EnvConfig
- Defined in:
- lib/cf/deploy/env_config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #app_name_for_colour(colour) ⇒ Object
- #app_names_for_colour(colour) ⇒ Object
- #app_names_for_manifest(manifest) ⇒ Object
- #apps_for_manifest(manifest) ⇒ Object
- #deployment_for_manifest(manifest) ⇒ Object
- #deployment_task_name(manifest) ⇒ Object
- #deployments ⇒ Object
- #flip_route(domain, hostname = nil) ⇒ Object
-
#initialize(name, deps, manifests, &block) ⇒ EnvConfig
constructor
A new instance of EnvConfig.
-
#manifest(manifest) ⇒ Object
Environment config setter methods.
- #manifests(manifests) ⇒ Object
- #route(domain, hostname_or_options = nil, options = nil) ⇒ Object
- #runtime_instances(instances) ⇒ Object
- #runtime_memory(memory) ⇒ Object
Constructor Details
#initialize(name, deps, manifests, &block) ⇒ EnvConfig
Returns a new instance of EnvConfig.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cf/deploy/env_config.rb', line 11 def initialize(name, deps, manifests, &block) merge!(name: name, task_name: EnvConfig.task_name(name), deps: deps, routes: [], runtime_memory: nil, runtime_instances: nil, manifests: manifests) instance_eval(&block) if block_given? raise "No manifests found for #{name}" if manifests.empty? self[:deployments] = deployments end |
Class Method Details
.task_name(name) ⇒ Object
7 8 9 |
# File 'lib/cf/deploy/env_config.rb', line 7 def self.task_name(name) "cf:deploy:#{name}" end |
Instance Method Details
#app_name_for_colour(colour) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/cf/deploy/env_config.rb', line 62 def app_name_for_colour(colour) self[:manifests].map do |manifest| name = app_names_for_manifest(File.(manifest.to_s)).first return name if name.include?(colour) end end |
#app_names_for_colour(colour) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/cf/deploy/env_config.rb', line 69 def app_names_for_colour(colour) self[:manifests].flat_map do |manifest| names = app_names_for_manifest(File.(manifest.to_s)) names if names.first.include?(colour) end.compact end |
#app_names_for_manifest(manifest) ⇒ Object
58 59 60 |
# File 'lib/cf/deploy/env_config.rb', line 58 def app_names_for_manifest(manifest) apps_for_manifest(manifest).map { |a| a[:name] } end |
#apps_for_manifest(manifest) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cf/deploy/env_config.rb', line 46 def apps_for_manifest(manifest) config = YAML.load_file(manifest) if config['applications'].nil? raise "No applications defined in YAML manifest #{manifest}" end config['applications'].map do |app| app.reduce({}) { |app, (k, v)| app.merge(k.to_sym => v) } end end |
#deployment_for_manifest(manifest) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/cf/deploy/env_config.rb', line 31 def deployment_for_manifest(manifest) { task_name: deployment_task_name(manifest), manifest: manifest, app_names: app_names_for_manifest(manifest), apps: apps_for_manifest(manifest) } end |
#deployment_task_name(manifest) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/cf/deploy/env_config.rb', line 38 def deployment_task_name(manifest) if self[:manifests].size > 1 EnvConfig.task_name(File.basename(manifest, '.yml').to_sym) else self[:task_name] end end |
#deployments ⇒ Object
27 28 29 |
# File 'lib/cf/deploy/env_config.rb', line 27 def deployments self[:manifests].map { |manifest| deployment_for_manifest(manifest) } end |
#flip_route(domain, hostname = nil) ⇒ Object
113 114 115 |
# File 'lib/cf/deploy/env_config.rb', line 113 def flip_route(domain, hostname = nil) self[:routes] << { domain: domain, hostname: hostname, flip: true } end |
#manifest(manifest) ⇒ Object
Environment config setter methods
78 79 80 |
# File 'lib/cf/deploy/env_config.rb', line 78 def manifest(manifest) self[:manifests] << manifest end |
#manifests(manifests) ⇒ Object
82 83 84 |
# File 'lib/cf/deploy/env_config.rb', line 82 def manifests(manifests) self[:manifests].concat(manifests) end |
#route(domain, hostname_or_options = nil, options = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cf/deploy/env_config.rb', line 94 def route(domain, = nil, = nil) if .nil? if .nil? hostname = nil = {} elsif .is_a?(String) hostname = = {} else hostname = nil = end else hostname = end self[:routes] << { domain: domain, hostname: hostname }.merge() end |
#runtime_instances(instances) ⇒ Object
90 91 92 |
# File 'lib/cf/deploy/env_config.rb', line 90 def runtime_instances(instances) self[:runtime_instances] = instances end |
#runtime_memory(memory) ⇒ Object
86 87 88 |
# File 'lib/cf/deploy/env_config.rb', line 86 def runtime_memory(memory) self[:runtime_memory] = memory end |