Sha256: 2b58c7d147dad762b032de879cc9da33601442fa007075928d81d9ab9e391dec

Contents?: true

Size: 510 Bytes

Versions: 1

Compression:

Stored size: 510 Bytes

Contents

class Duffel
  VERSION = "0.0.1"

  def self.method_missing(method, *args, &block)
    fetch_default = lambda do |key|
      raise KeyError.new("key not found: #{key}")
    end

    define_singleton_method(method) do |options=(args.first || {})|
      return_value = options.fetch(:fallback, fetch_default)
      fallback = return_value.is_a?(Proc) ? return_value : lambda { |key| return_value }

      env_name = method.to_s.upcase
      ENV.fetch(env_name, &fallback)
    end
    self.send(method)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duffel-0.0.1 lib/duffel.rb