Created
March 10, 2012 19:42
-
-
Save davidjrice/2012650 to your computer and use it in GitHub Desktop.
Clone heroku environment variables to a .env file for foreman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Clone heroku environment variables to a .env file for foreman'" | |
namespace :heroku do | |
namespace :env do | |
task :clone => :environment do | |
ignore_list = [ | |
"DATABASE_URL", | |
"GEM_PATH", | |
"LANG", | |
"LOG_LEVEL" | |
"PATH", | |
"RACK_ENV", | |
"RAILS_ENV", | |
"SHARED_DATABASE_URL", | |
] | |
puts 'Fetch heroku config' | |
config = `heroku config` | |
output = '' | |
config.lines.each do |line| | |
match = line.match(/([A-Z_]*)\s*=>\s*(\w*)/) | |
next if ignore_list.include?(match[1]) | |
output << "#{match[1]}=#{match[2]}\n" | |
end | |
file = "#{Rails.root}/.env" | |
puts "Outputting to #{file}" | |
File.open(file, "w+") do |f| | |
f.write(output) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment