Module: Kernel

Defined in:
lib/quickbooks/ruby_ext.rb,
lib/quickbooks/adaptability.rb,
lib/quickbooks/adapters/http_adapter.rb

Instance Method Summary collapse

Instance Method Details

#todo(task) ⇒ Object



125
126
127
128
# File 'lib/quickbooks/ruby_ext.rb', line 125

def todo(task)
  $TODO ||= []
  $TODO << task
end

#try_retry(times, *exception_classes) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/quickbooks/adaptability.rb', line 2

def try_retry(times, *exception_classes)
  options = exception_classes.last.is_a?(Hash) ? exception_classes.pop : {}
  raise ArgumentError unless block_given?
  retried = 0
  begin
    yield
  rescue *exception_classes => e
    puts "Error: #{e.inspect}. Retrying..." if $DEBUG
    options[:before_retry].call if options[:before_retry]
    retried += 1
    if retried < 2
      retry
    else
      raise e, "(Retried once)"
    end
  end
end