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
32 33 34 35 36 37 38 39 |
# File 'lib/dry/effects/providers/retry.rb', line 32 def attempt if attempts_exhausted? nil else @attempts += 1 yield end end |
#attempts_exhausted? ⇒ Boolean
41 42 43 |
# File 'lib/dry/effects/providers/retry.rb', line 41 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
45 46 47 |
# File 'lib/dry/effects/providers/retry.rb', line 45 def halt Halt[scope] end |
#provide?(effect) ⇒ Boolean
49 50 51 |
# File 'lib/dry/effects/providers/retry.rb', line 49 def provide?(effect) super && scope.equal?(effect.scope) end |
#represent ⇒ String
55 56 57 |
# File 'lib/dry/effects/providers/retry.rb', line 55 def represent "retry[#{scope} #{attempts}/#{limit}]" end |
#retry ⇒ Object
28 29 30 |
# File 'lib/dry/effects/providers/retry.rb', line 28 def retry Instructions.Raise(halt.new) end |