Module: Robustly::Methods

Defined in:
lib/robustly.rb

Instance Method Summary collapse

Instance Method Details

#safely(options = {}) ⇒ Object Also known as: yolo, robustly



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/robustly.rb', line 18

def safely(options = {})
  class_names = Array(options[:only] || StandardError)
  begin
    yield
  rescue *class_names => e
    raise e if %w(development test).include?(Robustly.env)
    if options[:throttle] ? rand < 1.0 / options[:throttle] : true
      begin
        Robustly.report_exception(e)
      rescue => e2
        $stderr.puts "FAIL-SAFE #{e2.class.name}: #{e2.message}"
      end
    end
    options[:default]
  end
end