Last Updated: February 25, 2016
·
1.74K
· passcod

Using Exceptional without a config.yml

This is completely undocumented behaviour which I deduced by reading the source:

Configure Exceptional in a Ruby (not Rack) app using an ENV variable instead of a config.yml file.

if ENV.include? 'EXCEPTIONAL_KEY'
  Exceptional::Config.api_key = ENV['EXCEPTIONAL_KEY']
end

Optional: a method that wraps it all up so you can bypass Exceptional in development

def exception_handle(opts = {}, &block)
  opts[:reraise] = true if opts[:reraise].nil?
  if ENV.include? 'EXCEPTIONAL_KEY'
    if opts[:reraise]
      Exceptional.rescue_and_reraise &block
    else
      Exceptional.rescue &block
    end
  else
    if opts[:reraise]
      block.call
    else
      begin
        block.call
      rescue Exception => e
        return e
      end
    end
  end
end

Because, y'know, using ENV variables is so damn more elegant than using config files, especially when developing open source stuff where you absolutely do not want to put credentials in source control (by accident).