retriable 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13cb5eedc133750c87f4678e0e94d1500e1d2c81ef474d0f38fd5ebff14b04a0
4
- data.tar.gz: 773776c2ff6ae25aa3cc4202eb851086274204955df5c602dd6b147a17015103
3
+ metadata.gz: 5961397b426eeaf2d2df8631f0a5dfe05adf52d5b9070ddbdf7b7825fd88f144
4
+ data.tar.gz: c982809ef09eb85ddedfcee95be53741846f6e4438af27e403c9ad4b020214c1
5
5
  SHA512:
6
- metadata.gz: 94477379cf7000dd9f81d0926ab02bfeffe31ebdec477ff930281cf8ba67f72c6fe78a116bb7e777f532bf0a58ae91da0a9b87c0dc927d51a754aaac36cef793
7
- data.tar.gz: 63f3d0141d5efa4bf789455c10607e85ba2a1fde60cf834ba500b48cfe1bd0f9993e7cefb8ee77beb87e5c0e75034d24860a826330ee920e51a9313353bcd472
6
+ metadata.gz: 30d8bfeeff407ab15fa9be7c2af2993142dce86d8406318e220afdb111c728b0c8c7cd2d6b105312ed9623074a5b20c88a9c19a6c33c3169d673d2276e0b52c4
7
+ data.tar.gz: f333fbf26eff94629f85f5d58688245025be3f39830bcad59da7f42ab52ad1506b155c03e1d96020a728b489ed016cb8ee1fcd5cde0a7a0ce3cfe59ad078c4d8
@@ -30,8 +30,6 @@ jobs:
30
30
  "4.0",
31
31
  jruby,
32
32
  ]
33
- env:
34
- CC_TEST_REPORTER_ID: 20a1139ef1830b4f813a10a03d90e8aa179b5226f75e75c5a949b25756ebf558
35
33
 
36
34
  steps:
37
35
  # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
@@ -63,3 +61,21 @@ jobs:
63
61
 
64
62
  - name: Run rubocop
65
63
  run: bundle exec rubocop
64
+
65
+ - name: Validate RBS
66
+ run: bundle exec rbs -I sig validate
67
+
68
+ audit:
69
+ runs-on: ubuntu-24.04
70
+
71
+ steps:
72
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
73
+
74
+ - name: Setup ruby
75
+ uses: ruby/setup-ruby@afeafc3d1ab54a631816aba4c914a0081c12ff2f # v1
76
+ with:
77
+ ruby-version: "3.3"
78
+ bundler-cache: true
79
+
80
+ - name: Run bundler-audit
81
+ run: bundle exec bundle-audit check --update
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # HEAD
2
2
 
3
+ ## 4.1.1
4
+
5
+ ### Bug fixes
6
+
7
+ - `retry_if`, `on_retry`, and `on_give_up` are now validated to be callable
8
+ (respond to `#call`) or falsy. A non-callable truthy value raises
9
+ `ArgumentError` at configuration time instead of a later `NoMethodError` on a
10
+ retry path. ([#140](https://github.com/kamui/retriable/pull/140))
11
+
12
+ ### Internal
13
+
14
+ - Add RBS type signatures for the public API (`Retriable.configure`, `config`,
15
+ `retriable`, `with_override`, `with_context`, and `Retriable::Config`) and
16
+ validate them in CI with `rbs validate`.
17
+ ([#142](https://github.com/kamui/retriable/pull/142))
18
+ - Enforce a minimum test coverage floor and add a `bundler-audit` dependency
19
+ audit job to CI. ([#143](https://github.com/kamui/retriable/pull/143))
20
+ - Remove an unused `CC_TEST_REPORTER_ID` from the CI workflow.
21
+ ([#141](https://github.com/kamui/retriable/pull/141))
22
+
3
23
  ## 4.1.0
4
24
 
5
25
  ### Bug fixes
data/Gemfile CHANGED
@@ -10,7 +10,9 @@ group :test do
10
10
  end
11
11
 
12
12
  group :development do
13
+ gem "bundler-audit", "~> 0.9"
13
14
  gem "listen", "~> 3.1"
15
+ gem "rbs", "~> 3.0", platforms: :ruby
14
16
  gem "rubocop", "~> 1.86"
15
17
  end
16
18
 
@@ -51,6 +51,9 @@ module Retriable
51
51
  end
52
52
 
53
53
  def validate!
54
+ validate_callable(:retry_if, retry_if)
55
+ validate_callable(:on_retry, on_retry)
56
+ validate_callable(:on_give_up, on_give_up)
54
57
  validate_on(on)
55
58
  validate_intervals
56
59
  if unbounded_tries?(tries)
@@ -28,6 +28,13 @@ module Retriable
28
28
  validate_non_negative_number(name, value)
29
29
  end
30
30
 
31
+ def validate_callable(name, value)
32
+ return unless value # nil/false disable the callback
33
+ return if value.respond_to?(:call)
34
+
35
+ raise ArgumentError, "#{name} must respond to #call or be nil"
36
+ end
37
+
31
38
  def validate_rand_factor
32
39
  return if finite_number?(rand_factor) && rand_factor >= 0 && rand_factor <= 1
33
40
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Retriable
4
- VERSION = "4.1.0"
4
+ VERSION = "4.1.1"
5
5
  end
data/sig/retriable.rbs CHANGED
@@ -1,4 +1,32 @@
1
1
  module Retriable
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+ OVERRIDE_THREAD_KEY: Symbol
4
+
5
+ def self.configure: () { (Config) -> void } -> void
6
+ def self.config: () -> Config
7
+ def self.with_override: (Hash[Symbol, untyped] options) { () -> untyped } -> untyped
8
+ def self.with_context: (Symbol context_key, ?Hash[Symbol, untyped] options) ?{ (Integer) -> untyped } -> untyped
9
+ def self.retriable: (?Hash[Symbol, untyped] options) { (Integer) -> untyped } -> untyped
10
+
11
+ class Config
12
+ ATTRIBUTES: Array[Symbol]
13
+
14
+ attr_accessor tries: Numeric
15
+ attr_accessor base_interval: Numeric
16
+ attr_accessor max_interval: Numeric
17
+ attr_accessor rand_factor: Numeric
18
+ attr_accessor multiplier: Numeric
19
+ attr_accessor sleep_disabled: bool
20
+ attr_accessor max_elapsed_time: Numeric?
21
+ attr_accessor intervals: Array[Numeric]?
22
+ attr_accessor on: untyped
23
+ attr_accessor retry_if: untyped
24
+ attr_accessor on_retry: untyped
25
+ attr_accessor on_give_up: untyped
26
+ attr_accessor contexts: Hash[Symbol, untyped]
27
+
28
+ def initialize: (?Hash[Symbol, untyped] opts) -> void
29
+ def to_h: () -> Hash[Symbol, untyped]
30
+ def validate!: () -> void
31
+ end
4
32
  end
data/spec/config_spec.rb CHANGED
@@ -163,4 +163,21 @@ describe Retriable::Config do
163
163
  .to raise_error(ArgumentError, /on must be an Exception class/)
164
164
  end
165
165
  end
166
+
167
+ context "callable option validation" do
168
+ %i[retry_if on_retry on_give_up].each do |opt|
169
+ it "accepts a callable for #{opt}" do
170
+ expect { described_class.new(opt => ->(*) {}) }.not_to raise_error
171
+ end
172
+
173
+ it "accepts nil and false for #{opt}" do
174
+ expect { described_class.new(opt => nil) }.not_to raise_error
175
+ expect { described_class.new(opt => false) }.not_to raise_error
176
+ end
177
+
178
+ it "rejects a non-callable truthy value for #{opt}" do
179
+ expect { described_class.new(opt => 5) }.to raise_error(ArgumentError, /#{opt}.*#call/)
180
+ end
181
+ end
182
+ end
166
183
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "simplecov"
4
- SimpleCov.start
4
+ SimpleCov.start do
5
+ minimum_coverage 95
6
+ end
5
7
 
6
8
  require "pry"
7
9
  require_relative "../lib/retriable"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retriable
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Chu