Skip to content

Instantly share code, notes, and snippets.

@kjlape
Created February 21, 2018 17:14
Show Gist options
  • Select an option

  • Save kjlape/5063eac6118609c9d4d9b9462c54ca7a to your computer and use it in GitHub Desktop.

Select an option

Save kjlape/5063eac6118609c9d4d9b9462c54ca7a to your computer and use it in GitHub Desktop.
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