lib/grumlin/repository/error_handling_strategy.rb in grumlin-0.23.0 vs lib/grumlin/repository/error_handling_strategy.rb in grumlin-1.0.0.rc1
- old
+ new
@@ -1,44 +1,40 @@
# frozen_string_literal: true
-module Grumlin
- module Repository
- class ErrorHandlingStrategy
- def initialize(mode: :retry, **params)
- @mode = mode
- @params = params
- @on_exceptions = params[:on]
- end
+class Grumlin::Repository::ErrorHandlingStrategy
+ def initialize(mode: :retry, **params)
+ @mode = mode
+ @params = params
+ @on_exceptions = params[:on]
+ end
- def raise?
- @mode == :raise
- end
+ def raise?
+ @mode == :raise
+ end
- def ignore?
- @mode == :ignore
- end
+ def ignore?
+ @mode == :ignore
+ end
- def retry?
- @mode == :retry
- end
+ def retry?
+ @mode == :retry
+ end
- def apply!(&block)
- return yield if raise?
- return ignore_errors!(&block) if ignore?
+ def apply!(&block)
+ return yield if raise?
+ return ignore_errors!(&block) if ignore?
- retry_errors!(&block)
- end
+ retry_errors!(&block)
+ end
- private
+ private
- def ignore_errors!
- yield
- rescue *@on_exceptions
- # ignore errors
- end
+ def ignore_errors!
+ yield
+ rescue *@on_exceptions
+ # ignore errors
+ end
- def retry_errors!(&block)
- Retryable.retryable(**@params, &block)
- end
- end
+ def retry_errors!(&block)
+ Retryable.retryable(**@params, &block)
end
end