Skip to content

Instantly share code, notes, and snippets.

@jlthai
Last active January 28, 2019 19:21
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 jlthai/e97d5fe893ec9053c85811930409b8a8 to your computer and use it in GitHub Desktop.
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.
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
@jlthai
Copy link
Author

jlthai commented Jan 28, 2019

Potential clash with local ENVs, I can always do an environment check explicitly instead of always checking ENV first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment