Skip to content

Instantly share code, notes, and snippets.

@dinatih
Last active June 29, 2018 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinatih/c0defb7a332fd389d34d8400dd7ec943 to your computer and use it in GitHub Desktop.
Save dinatih/c0defb7a332fd389d34d8400dd7ec943 to your computer and use it in GitHub Desktop.
Add Rails.heroku_env (like Rails.env) to know in which heroku environment you are (Based on HEROKU_APP_NAME, that you can get from runtime-dyno-metadata labs plugin )
# config/initializers/rails.rb
# Based on Rails.env http://api.rubyonrails.org/classes/Rails.html#method-c-env
module Rails
# Use runtime-dyno-metadata labs plugin. See https://devcenter.heroku.com/articles/dyno-metadata
class << self
def heroku_env
if @_heroku_env
@_heroku_env
elsif ENV['HEROKU_APP_NAME']
production_app_names = ['myapp-prod', 'myapp-beta']
heroku_env = production_app_names.include?(ENV['HEROKU_APP_NAME']) ? 'production' : 'staging'
@_heroku_env = ActiveSupport::StringInquirer.new(heroku_env)
else
@_heroku_env = ActiveSupport::StringInquirer.new('development')
end
end
def heroku_env=(environment)
@_heroku_env = ActiveSupport::StringInquirer.new(environment)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment