Sha256: e48d838b41a01f595b825653ef428ceec92d0296bb94d74b1e63031e651fcf89

Contents?: true

Size: 767 Bytes

Versions: 20

Compression:

Stored size: 767 Bytes

Contents

# frozen_string_literal: true

module Grumlin
  module Repository
    class 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
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
grumlin-0.23.0 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.22.5 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.22.4 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.22.3 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.22.2 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.22.1 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.22.0 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.21.1 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.21.0 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.20.2 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.20.1 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.20.0 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.7 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.6 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.5 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.4 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.3 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.2 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.1 lib/grumlin/repository/error_handling_strategy.rb
grumlin-0.19.0 lib/grumlin/repository/error_handling_strategy.rb