module Figaro::ENV

Public Instance Methods

respond_to?(method, *) click to toggle source
Calls superclass method
# File lib/figaro/env.rb, line 5
def respond_to?(method, *)
  key, punctuation = extract_key_from_method(method)

  case punctuation
  when "!" then ::ENV.keys.any? { |k| k.upcase == key } || super
  when "?", nil then true
  else super
  end
end

Private Instance Methods

extract_key_from_method(method) click to toggle source
# File lib/figaro/env.rb, line 29
def extract_key_from_method(method)
  method.to_s.upcase.match(/^(.+?)([!?=])?$/).captures
end
method_missing(method, *) click to toggle source
Calls superclass method
# File lib/figaro/env.rb, line 17
def method_missing(method, *)
  key, punctuation = extract_key_from_method(method)
  _, value = ::ENV.detect { |k, _| k.upcase == key }

  case punctuation
  when "!" then value || missing_key!(key)
  when "?" then !!value
  when nil then value
  else super
  end
end
missing_key!(key) click to toggle source
# File lib/figaro/env.rb, line 33
def missing_key!(key)
  raise MissingKey.new("Missing required Figaro configuration key #{key.inspect}.")
end