Class: Dry::Effects::Providers::Retry

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/effects/providers/retry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



11
12
13
# File 'lib/dry/effects/providers/retry.rb', line 11

def attempts
  @attempts
end

#limitObject (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

#attemptObject



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

Returns:

  • (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

#haltObject



45
46
47
# File 'lib/dry/effects/providers/retry.rb', line 45

def halt
  Halt[scope]
end

#provide?(effect) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/dry/effects/providers/retry.rb', line 49

def provide?(effect)
  super && scope.equal?(effect.scope)
end

#representString

Returns:

  • (String)


55
56
57
# File 'lib/dry/effects/providers/retry.rb', line 55

def represent
  "retry[#{scope} #{attempts}/#{limit}]"
end

#retryObject



28
29
30
# File 'lib/dry/effects/providers/retry.rb', line 28

def retry
  Instructions.Raise(halt.new)
end