Module: RescueExt

Defined in:
lib/ventouse/rescue_ext.rb

Instance Method Summary collapse

Instance Method Details

#rescue_all(default = nil, silent = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ventouse/rescue_ext.rb', line 4

def rescue_all default = nil, silent = false
  begin
    return yield
  rescue Exception => e
    unless silent
      Rails.logger.warn "Exception rescued:"
      Rails.logger.warn e
      if e.respond_to? :io
        Rails.logger.warn "URI: '#{e.io.meta['location']}'"
      end
      Rails.logger.warn e.backtrace.join("\n")
    end

    return default
  end
end

#silently_rescue_all(default = nil, &block) ⇒ Object



21
22
23
# File 'lib/ventouse/rescue_ext.rb', line 21

def silently_rescue_all default = nil, &block
  rescue_all default, true, &block
end

#timeout(sec, default = nil) ⇒ Object



25
26
27
# File 'lib/ventouse/rescue_ext.rb', line 25

def timeout sec, default = nil
  rescue_all(default) {Timeout.timeout(sec) { yield }}
end