Last active
January 28, 2019 19:21
-
-
Save jlthai/e97d5fe893ec9053c85811930409b8a8 to your computer and use it in GitHub Desktop.
Quick way to use ENVs from Heroku config while using Rails 5.2 style credentials for development.
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
module AppConfig | |
def self.get(key) | |
env_val = ENV[key.to_s] | |
return env_val if env_val.present? | |
rails_credentials = Rails.application.credentials | |
# Tries finding a key with the first part being nested first. | |
# :aws_access_key_id will attempt to grab | |
# { aws: { access_key_id: 'val' } } | |
# before attempting | |
# { aws_access_key_id: 'val' } | |
rails_credentials.dig(*key.to_s.split("_", 2).map(&:to_sym)) || | |
rails_credentials.dig(key.to_sym) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Potential clash with local ENVs, I can always do an environment check explicitly instead of always checking ENV first.