Class: Dry::Effects::Providers::Retry
- Inherits:
-
Object
- Object
- Dry::Effects::Providers::Retry
- Defined in:
- lib/dry/effects/providers/retry.rb
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
- #attempt ⇒ Object
- #attempts_exhausted? ⇒ Boolean
-
#call(limit, &block) ⇒ Object
private
Yield the block with the handler installed.
- #halt ⇒ Object
- #provide?(effect) ⇒ Boolean
- #represent ⇒ String
- #retry ⇒ Object
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
11 12 13 |
# File 'lib/dry/effects/providers/retry.rb', line 11 def attempts @attempts end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
13 14 15 |
# File 'lib/dry/effects/providers/retry.rb', line 13 def limit @limit end |
Instance Method Details
#attempt ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/dry/effects/providers/retry.rb', line 30 def attempt if attempts_exhausted? nil else @attempts += 1 yield end end |
#attempts_exhausted? ⇒ Boolean
39 40 41 |
# File 'lib/dry/effects/providers/retry.rb', line 39 def attempts_exhausted? attempts.equal?(limit) end |
#call(limit, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yield the block with the handler installed
18 19 20 21 22 23 24 25 26 |
# File 'lib/dry/effects/providers/retry.rb', line 18 def call(limit, &block) @limit = limit @attempts = 0 loop do return attempt(&block) rescue halt # rubocop:disable Lint/SuppressedException end end |
#halt ⇒ Object
43 |
# File 'lib/dry/effects/providers/retry.rb', line 43 def halt = Halt[scope] |
#provide?(effect) ⇒ Boolean
45 |
# File 'lib/dry/effects/providers/retry.rb', line 45 def provide?(effect) = super && scope.equal?(effect.scope) |
#represent ⇒ String
49 |
# File 'lib/dry/effects/providers/retry.rb', line 49 def represent = "retry[#{scope} #{attempts}/#{limit}]" |
#retry ⇒ Object
28 |
# File 'lib/dry/effects/providers/retry.rb', line 28 def retry = Instructions.Raise(halt.new) |