Last active
June 29, 2018 13:53
-
-
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 )
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
# 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