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
- #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_memory(memory) ⇒ Object
Constructor Details
#initialize(name, deps, manifests, &block) ⇒ EnvConfig
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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, 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
54 55 56 57 58 59 |
# File 'lib/cf/deploy/env_config.rb', line 54 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
61 62 63 64 65 66 |
# File 'lib/cf/deploy/env_config.rb', line 61 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
44 45 46 47 48 49 50 51 52 |
# File 'lib/cf/deploy/env_config.rb', line 44 def app_names_for_manifest(manifest) config = YAML.load_file(manifest) if config['applications'].nil? raise "No applications defined in YAML manifest #{manifest}" end config['applications'].map { |a| a['name'] } end |
#deployment_for_manifest(manifest) ⇒ Object
30 31 32 33 34 |
# File 'lib/cf/deploy/env_config.rb', line 30 def deployment_for_manifest(manifest) { task_name: deployment_task_name(manifest), manifest: manifest, app_names: app_names_for_manifest(manifest) } end |
#deployment_task_name(manifest) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/cf/deploy/env_config.rb', line 36 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
26 27 28 |
# File 'lib/cf/deploy/env_config.rb', line 26 def deployments self[:manifests].map { |manifest| deployment_for_manifest(manifest) } end |
#flip_route(domain, hostname = nil) ⇒ Object
101 102 103 |
# File 'lib/cf/deploy/env_config.rb', line 101 def flip_route(domain, hostname = nil) self[:routes] << { domain: domain, hostname: hostname, flip: true } end |
#manifest(manifest) ⇒ Object
Environment config setter methods
70 71 72 |
# File 'lib/cf/deploy/env_config.rb', line 70 def manifest(manifest) self[:manifests] << manifest end |
#manifests(manifests) ⇒ Object
74 75 76 |
# File 'lib/cf/deploy/env_config.rb', line 74 def manifests(manifests) self[:manifests].concat(manifests) end |
#route(domain, hostname_or_options = nil, options = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cf/deploy/env_config.rb', line 82 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_memory(memory) ⇒ Object
78 79 80 |
# File 'lib/cf/deploy/env_config.rb', line 78 def runtime_memory(memory) self[:runtime_memory] = memory end |