Sha256: 8d6875e864bb18f752bab701f6d2f73a9f0016472b18aed26f54a92288a91547

Contents?: true

Size: 623 Bytes

Versions: 15

Compression:

Stored size: 623 Bytes

Contents

# frozen_string_literal: true

class Grumlin::Repository::ErrorHandlingStrategy
  def initialize(mode: :retry, **params)
    @mode = mode
    @params = params
    @on_exceptions = params[:on]
  end

  def raise?
    @mode == :raise
  end

  def ignore?
    @mode == :ignore
  end

  def retry?
    @mode == :retry
  end

  def apply!(&block)
    return yield if raise?
    return ignore_errors!(&block) if ignore?

    retry_errors!(&block)
  end

  private

  def ignore_errors!
    yield
  rescue *@on_exceptions
    # ignore errors
  end

  def retry_errors!(&block)
    Retryable.retryable(**@params, &block)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grumlin-1.2.0 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.1.0 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.4 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.3 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.3.beta1 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.2 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.1 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0.rc7 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0.rc6 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0.rc5 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0.rc4 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0.rc3 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0.rc2 lib/grumlin/repository/error_handling_strategy.rb
grumlin-1.0.0.rc1 lib/grumlin/repository/error_handling_strategy.rb