Module: Robustly::Methods

Defined in:
lib/robustly.rb

Instance Method Summary collapse

Instance Method Details

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



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

def safely(options = {}, &block)
  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
      Robustly.report_exception(e)
    end
    options[:default]
  end
end