summaryrefslogtreecommitdiff
path: root/lib/expand_variables.rb
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-09-13 14:14:55 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-09-19 10:05:35 +0200
commita4638dddf22797f46d72ea7b73c8453ba68645ab (patch)
tree3b270989070a48e9e1ea3f983070168f863c4bd1 /lib/expand_variables.rb
parent1d51bc7dfd04886fa5af69a60bb509691d697813 (diff)
downloadgitlab-ce-a4638dddf22797f46d72ea7b73c8453ba68645ab.tar.gz
Add support for dynamic environments
Environments that can have a URL with predefined CI variables.
Diffstat (limited to 'lib/expand_variables.rb')
-rw-r--r--lib/expand_variables.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/expand_variables.rb b/lib/expand_variables.rb
new file mode 100644
index 00000000000..40bf9483eb5
--- /dev/null
+++ b/lib/expand_variables.rb
@@ -0,0 +1,15 @@
+String.instance_eval
+ def expand_variables(variables)
+ # Convert hash array to variables
+ if variables.is_a?(Array)
+ variables = variables.reduce({}) do |hash, variable|
+ hash[variable[:key]] = variable[:value]
+ hash
+ end
+ end
+
+ self.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
+ variables[$1 || $2]
+ end
+ end
+end