Skip to content

Instantly share code, notes, and snippets.

@AndyObtiva
Last active August 29, 2015 13:55
Show Gist options
  • Save AndyObtiva/8763150 to your computer and use it in GitHub Desktop.
Save AndyObtiva/8763150 to your computer and use it in GitHub Desktop.
Heroku Config Parser in Ruby
# Parses configuration out from the "heroku config" command, and converts to command-line input
# for the "heroku config:add" command. It escapes $ characters.
def parse(config_text)
config_line_regex = /([^:]+):(.*)/
config_text.split("\n").map do |line|
line_match = line.match(config_line_regex)
[line_match[1], line_match[2]]
end.map do |name, value|
"#{name.strip}=\"#{value.strip.gsub("$", "\\$")}\""
end.join(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment