Created
June 13, 2013 08:15
-
-
Save ys/5772055 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
module Env | |
class EnvKeyError < StandardError; end | |
def self.method_missing(method_name, *arguments, &block) | |
env_value(method_name) { raise EnvKeyError, method_name } | |
end | |
def self.respond_to?(method_name, include_private = false) | |
env_value(method_name) | |
true | |
rescue StandardError | |
false | |
end | |
def self.method_to_key(method_name) | |
method_name.to_s.upcase | |
end | |
def self.env_value(method_name, &block) | |
block ||= -> { false } | |
ENV.fetch(method_to_key(method_name), &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment