gitlab-org--gitlab-foss/lib/expand_variables.rb

18 lines
427 B
Ruby
Raw Normal View History

module ExpandVariables
class << self
def expand_variables(value, 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
value.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
variables[$1 || $2]
end
end
end
end