Created
February 21, 2018 17:14
-
-
Save kjlape/5063eac6118609c9d4d9b9462c54ca7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require 'active_support' | |
| require 'active_support/core_ext/object/blank' | |
| def fetch(key, default: nil, scope: :rails) | |
| value = fetch_with_scope(key, scope, default: default) | |
| value.presence || raise(KeyError, "value for key #{key} cannot be blank") | |
| end | |
| def fetch_with_scope(key, scope, default: nil) | |
| ENV.fetch("#{scope.to_s.upcase}_#{key}") do | |
| ENV.fetch(key, *default) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment