Class: CF::Deploy::Config
- Inherits:
-
Hash
- Object
- Hash
- CF::Deploy::Config
- Defined in:
- lib/cf/deploy/config.rb
Constant Summary collapse
- VALID_CF_KEYS =
[:api, :username, :password, :organisation, :space]
Instance Attribute Summary collapse
-
#environments_to_be_loaded ⇒ Object
readonly
Returns the value of attribute environments_to_be_loaded.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #api(api) ⇒ Object
- #environment(env, &block) ⇒ Object
- #environments(manifests_by_env) ⇒ Object
- #from_env(key) ⇒ Object
-
#initialize(&block) ⇒ Config
constructor
A new instance of Config.
- #manifest_env(manifest) ⇒ Object
-
#manifest_glob(glob) ⇒ Object
Config setter methods.
- #manifests_by_env ⇒ Object
- #organisation(organisation) ⇒ Object
- #password(password) ⇒ Object
- #space(space) ⇒ Object
- #username(username) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cf/deploy/config.rb', line 8 def initialize(&block) @environments_to_be_loaded = [] merge!(manifest_glob: 'manifests/*', api: nil, username: nil, password: nil, organisation: nil, space: nil) instance_eval(&block) if block_given? self[:environments] = environments(manifests_by_env) end |
Instance Attribute Details
#environments_to_be_loaded ⇒ Object (readonly)
Returns the value of attribute environments_to_be_loaded.
6 7 8 |
# File 'lib/cf/deploy/config.rb', line 6 def environments_to_be_loaded @environments_to_be_loaded end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 |
# File 'lib/cf/deploy/config.rb', line 23 def [](key) from_env(key) || super end |
#api(api) ⇒ Object
76 |
# File 'lib/cf/deploy/config.rb', line 76 def api(api) self[:api] = api end |
#environment(env, &block) ⇒ Object
81 |
# File 'lib/cf/deploy/config.rb', line 81 def environment(env, &block) @environments_to_be_loaded << [env, block] end |
#environments(manifests_by_env) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cf/deploy/config.rb', line 50 def environments(manifests_by_env) environments = [] environments_to_be_loaded.each do |(env, block)| if env.is_a?(Hash) name, deps = env.first deps = (['cf:login'] << deps).flatten else name = env deps = ['cf:login'] end manifests = manifests_by_env.delete(name) || [] environments << EnvConfig.new(name, deps, manifests, &block) end manifests_by_env.each do |(name, manifests)| environments << EnvConfig.new(name, ['cf:login'], manifests) end environments end |
#from_env(key) ⇒ Object
27 28 29 |
# File 'lib/cf/deploy/config.rb', line 27 def from_env(key) ENV["CF_#{key.upcase}"] if VALID_CF_KEYS.include?(key) end |
#manifest_env(manifest) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/cf/deploy/config.rb', line 40 def manifest_env(manifest) if manifest =~ /_blue.yml$/ File.basename(manifest, '_blue.yml').to_sym elsif manifest =~ /_green.yml$/ File.basename(manifest, '_green.yml').to_sym else File.basename(manifest, '.yml').to_sym end end |
#manifest_glob(glob) ⇒ Object
Config setter methods
75 |
# File 'lib/cf/deploy/config.rb', line 75 def manifest_glob(glob) self[:manifest_glob] = glob end |
#manifests_by_env ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/cf/deploy/config.rb', line 31 def manifests_by_env Dir[self[:manifest_glob]].reduce({}) do |envs, manifest| env = manifest_env(manifest) envs[env] ||= [] envs[env] << manifest envs end end |
#organisation(organisation) ⇒ Object
79 |
# File 'lib/cf/deploy/config.rb', line 79 def organisation(organisation) self[:organisation] = organisation end |
#password(password) ⇒ Object
78 |
# File 'lib/cf/deploy/config.rb', line 78 def password(password) self[:password] = password end |
#space(space) ⇒ Object
80 |
# File 'lib/cf/deploy/config.rb', line 80 def space(space) self[:space] = space end |
#username(username) ⇒ Object
77 |
# File 'lib/cf/deploy/config.rb', line 77 def username(username) self[:username] = username end |