Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--require spec_helper
--format documentation
--color
--require spec_helper
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --require spec_helper option is duplicated on lines 1 and 3. Remove the duplicate on line 3 to avoid redundancy.

Suggested change
--require spec_helper

Copilot uses AI. Check for mistakes.
12 changes: 9 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/Documentation:
Enabled: false

Expand All @@ -10,10 +13,10 @@ Style/TrailingCommaInArguments:
Lint/InheritException:
Enabled: false

Layout/IndentArray:
Layout/FirstArrayElementIndentation:
Enabled: false

Layout/IndentHash:
Layout/FirstHashElementIndentation:
Enabled: false

Style/NegatedIf:
Expand All @@ -25,7 +28,7 @@ Metrics/ClassLength:
Metrics/ModuleLength:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Max: 120

Metrics/MethodLength:
Expand All @@ -36,3 +39,6 @@ Metrics/BlockLength:

Metrics/AbcSize:
Enabled: false

Style/TrailingCommaInArrayLiteral:
Enabled: false
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Require ruby 2.3+.
- Fix: Ensure `tries` value is overridden by `intervals` parameter if both are provided and add a test for this. This is always what the README stated but the code didn't actually do it.
- Fix: Some rubocop offenses.

## 3.1.2

Expand Down
10 changes: 10 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Code of Conduct

"retriable" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):

* Participants will be tolerant of opposing views.
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
* When interpreting the words and actions of others, participants should always assume good intentions.
* Behaviour which can be reasonably considered harassment will not be tolerated.

If you have any concerns about behaviour within this project, please contact us at ["jack@jackchu.com"](mailto:"jack@jackchu.com").
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mailto link should not have quotes around the email address. Change ["jack@jackchu.com"](mailto:"jack@jackchu.com") to [jack@jackchu.com](mailto:jack@jackchu.com). The quotes break the mailto link formatting.

Suggested change
If you have any concerns about behaviour within this project, please contact us at ["jack@jackchu.com"](mailto:"jack@jackchu.com").
If you have any concerns about behaviour within this project, please contact us at [jack@jackchu.com](mailto:jack@jackchu.com).

Copilot uses AI. Check for mistakes.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec
Expand All @@ -13,4 +15,5 @@ end

group :development, :test do
gem "pry"
gem "rake", "~> 13.0"
end
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[spec rubocop]
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "retriable"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
5 changes: 5 additions & 0 deletions lib/retriable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "timeout"
require_relative "retriable/config"
require_relative "retriable/exponential_backoff"
Expand Down Expand Up @@ -58,6 +60,7 @@ def retriable(opts = {})

begin
return Timeout.timeout(timeout) { return yield(try) } if timeout

return yield(try)
rescue *[*exception_list] => exception
if on.is_a?(Hash)
Expand All @@ -68,7 +71,9 @@ def retriable(opts = {})

interval = intervals[index]
on_retry.call(exception, try, elapsed_time.call, interval) if on_retry

raise if try >= tries || (elapsed_time.call + interval) > max_elapsed_time

sleep interval if sleep_disabled != true
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/retriable/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "exponential_backoff"

module Retriable
Expand Down Expand Up @@ -32,6 +34,7 @@ def initialize(opts = {})

opts.each do |k, v|
raise ArgumentError, "#{k} is not a valid option" if !ATTRIBUTES.include?(k)

instance_variable_set(:"@#{k}", v)
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/retriable/core_ext/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../../retriable"

module Kernel
Expand Down
2 changes: 2 additions & 0 deletions lib/retriable/exponential_backoff.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Retriable
class ExponentialBackoff
ATTRIBUTES = [
Expand Down
4 changes: 3 additions & 1 deletion lib/retriable/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Retriable
VERSION = "3.2.0".freeze
VERSION = "3.2.0"
end
2 changes: 1 addition & 1 deletion retriable.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# coding: utf-8
# frozen_string_literal: true
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "retriable/version"
Expand Down
4 changes: 4 additions & 0 deletions sig/retriable.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Retriable
VERSION: String
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
end
2 changes: 2 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Retriable::Config do
let(:default_config) { described_class.new }

Expand Down
2 changes: 2 additions & 0 deletions spec/exponential_backoff_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Retriable::ExponentialBackoff do
context "defaults" do
let(:backoff_config) { described_class.new }
Expand Down
4 changes: 3 additions & 1 deletion spec/retriable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe Retriable do
let(:time_table_handler) do
->(_exception, try, _elapsed_time, next_interval) { @next_interval_table[try] = next_interval }
Expand Down Expand Up @@ -144,7 +146,7 @@ def increment_tries_with_exception(exception_class = nil)
max_interval: 100.0,
rand_factor: 0.8,
multiplier: 2.0,
on_retry: time_table_handler
on_retry: time_table_handler,
) do
increment_tries_with_exception
end
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

require "simplecov"
SimpleCov.start

require "pry"
require_relative "../lib/retriable"
require_relative "support/exceptions.rb"
require_relative "support/exceptions"

RSpec.configure do |config|
config.before(:each) do
Expand Down
2 changes: 2 additions & 0 deletions spec/support/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class NonStandardError < Exception; end
class SecondNonStandardError < NonStandardError; end
class DifferentError < Exception; end