Skip to content

Commit

Permalink
heroku task for env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
mattvanhorn committed Jul 8, 2012
1 parent 46600c4 commit dea6ab4
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/tasks/heroku.thor
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/string/inflections'

module Deploy
extend self

module Support
private

def heroku(command)
command "heroku #{command} --app #{heroku_app}"
end

def command(command)
puts command
system command
end

def environment
self.class.to_s.demodulize.underscore
end

def heroku_env
@heroku_env ||= Deploy.heroku_config[environment]
end

def heroku_app
@heroku_app ||= Deploy.heroku_config[:apps][environment]
end
end

def self.commands_for_environment(app_env)
module_eval do
klass = Class.new(Thor) do
include Support

desc "rack_env", "Set the RACK_ENV config variable"
def rack_env
heroku("config:add RACK_ENV=#{environment}")
end

desc "config", "Set config variables"
def config
env_values = [].tap do |e|
heroku_env.each do |key, value|
e << "#{key.upcase}='#{value}'"
end
end
heroku("config:add #{env_values.join(' ')}")
end
end

const_set(app_env.classify, klass)
end
end

def heroku_config
@heroku_config ||= YAML.load_file(File.expand_path('../../../config/heroku.yml', __FILE__)).with_indifferent_access
end

heroku_config[:apps].each_key do |app_env|
commands_for_environment(app_env)
end
end

0 comments on commit dea6ab4

Please sign in to comment.