From a4638dddf22797f46d72ea7b73c8453ba68645ab Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 13 Sep 2016 14:14:55 +0200 Subject: Add support for dynamic environments Environments that can have a URL with predefined CI variables. --- lib/expand_variables.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/expand_variables.rb (limited to 'lib/expand_variables.rb') 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 -- cgit v1.2.3