Class: PropertyGenerator::Globals
- Inherits:
-
Object
- Object
- PropertyGenerator::Globals
- Defined in:
- lib/generator/globals.rb
Instance Attribute Summary collapse
-
#globals ⇒ Object
Returns the value of attribute globals.
Instance Method Summary collapse
-
#condense_globals ⇒ Object
merge environment globals with account globals.
- #get_account_globals ⇒ Object
- #get_environment_globals ⇒ Object
- #get_main_global ⇒ Object
-
#initialize(project_path, config) ⇒ Globals
constructor
A new instance of Globals.
Constructor Details
#initialize(project_path, config) ⇒ Globals
Returns a new instance of Globals.
6 7 8 9 10 11 |
# File 'lib/generator/globals.rb', line 6 def initialize(project_path, config) @project_path = project_path @environments = config.environments @environment_configs = config.environment_configs @accounts = config.accounts end |
Instance Attribute Details
#globals ⇒ Object
Returns the value of attribute globals.
4 5 6 |
# File 'lib/generator/globals.rb', line 4 def globals @globals end |
Instance Method Details
#condense_globals ⇒ Object
merge environment globals with account globals.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generator/globals.rb', line 51 def condense_globals condensed = {} # get account and the environmental hash's for said account environment_globals = get_environment_globals account_globals = get_account_globals main_global = get_main_global # nothing to do here if everything is empty return condensed if environment_globals.empty? && account_globals.empty? && main_global.empty? environment_globals.each do |account, env_global | # get the env and the values env_global.each do |env, hash| account_globals[account] ||= {} # set the environment globals to be the account global merged with the env globals env_global[env] = account_globals[account].merge(hash) unless hash.empty? condensed[env] = env_global[env] end end unless main_global.empty? # All environments need the main global definitions @environments.each do |env| # If a key/value pair for a environment has not been defined set one so we can merge condensed[env] ||= {} # We need to merge into the globals so any env configs overwrite main global configs. # Dup so we dont modify the original object main_global_dup = main_global.dup condensed[env] = main_global_dup.merge(condensed[env]) end end condensed end |
#get_account_globals ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/generator/globals.rb', line 26 def get_account_globals data = {} @accounts.each do |account| next unless Dir.exists?("#{@project_path}/globals/accounts/#{account}") account_default_file = "#{@project_path}/globals/accounts/#{account}/#{account}.yml" data[account] = YAML.load_file(account_default_file) if File.exists?(account_default_file) end data end |
#get_environment_globals ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generator/globals.rb', line 36 def get_environment_globals data = {} @accounts.each do |account| next unless Dir.exists?("#{@project_path}/globals/accounts/#{account}/environments") data[account] = {} @environments.each do |env| next unless File.exists?("#{@project_path}/globals/accounts/#{account}/environments/#{env}.yml") data[account][env] = YAML.load_file("#{@project_path}/globals/accounts/#{account}/environments/#{env}.yml") end end data end |
#get_main_global ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/generator/globals.rb', line 18 def get_main_global top_level = {} if File.exists?("#{@project_path}/globals/globals.yml") top_level = YAML.load_file("#{@project_path}/globals/globals.yml") end top_level end |