Skip to content

Commit

Permalink
Bugfix: Account globals are ignored if there are no env globals (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreene-r7 authored Jan 11, 2023
1 parent aec6e43 commit 2bd88b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
cps-property-generator-*.gem
out/

19 changes: 19 additions & 0 deletions lib/generator/globals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ def condense_globals
end
end

# If there are no environmental globals and there are account globals we have to merge them in
if condensed.empty? && !account_globals.empty?
# assemble the account to env mapping
mapping = {}

@environment_configs.each do |env, vals|
account = vals["account"]
next if account.nil?

mapping[account] = Array(mapping[account]).push(env)
end

account_globals.each do |account, env_account|
mapping[account].each do |env|
condensed[env] = env_account
end
end
end

unless main_global.empty?
# All environments need the main global definitions
@environments.each do |env|
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/global_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module PropertyGenerator
expect(global.get_account_globals).to eq({
123456789012 => {
'my_account' => 123456789012
},
987654321098 => {
'my_account' => 987654321098
}
})
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my_account: 987654321098

0 comments on commit 2bd88b8

Please sign in to comment.