From f7a4c33211cf03783c2fc64dfc447ac658543e87 Mon Sep 17 00:00:00 2001 From: Jack Chu Date: Wed, 18 Feb 2026 12:16:34 -0500 Subject: [PATCH] Fix some rubocop linting errors, fill in some files from new generated gem scaffolding --- .rspec | 3 ++- .rubocop.yml | 12 +++++++++--- CHANGELOG.md | 1 + CODE_OF_CONDUCT.md | 10 ++++++++++ Gemfile | 3 +++ Rakefile | 12 ++++++++++++ bin/console | 11 +++++++++++ bin/setup | 8 ++++++++ lib/retriable.rb | 5 +++++ lib/retriable/config.rb | 3 +++ lib/retriable/core_ext/kernel.rb | 2 ++ lib/retriable/exponential_backoff.rb | 2 ++ lib/retriable/version.rb | 4 +++- retriable.gemspec | 2 +- sig/retriable.rbs | 4 ++++ spec/config_spec.rb | 2 ++ spec/exponential_backoff_spec.rb | 2 ++ spec/retriable_spec.rb | 4 +++- spec/spec_helper.rb | 4 +++- spec/support/exceptions.rb | 2 ++ 20 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 Rakefile create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 sig/retriable.rbs diff --git a/.rspec b/.rspec index 5be63fc..34c5164 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ ---require spec_helper --format documentation +--color +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml index 4b695e3..835f025 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,9 @@ Style/StringLiterals: EnforcedStyle: double_quotes +Style/StringLiteralsInInterpolation: + EnforcedStyle: double_quotes + Style/Documentation: Enabled: false @@ -10,10 +13,10 @@ Style/TrailingCommaInArguments: Lint/InheritException: Enabled: false -Layout/IndentArray: +Layout/FirstArrayElementIndentation: Enabled: false -Layout/IndentHash: +Layout/FirstHashElementIndentation: Enabled: false Style/NegatedIf: @@ -25,7 +28,7 @@ Metrics/ClassLength: Metrics/ModuleLength: Enabled: false -Metrics/LineLength: +Layout/LineLength: Max: 120 Metrics/MethodLength: @@ -36,3 +39,6 @@ Metrics/BlockLength: Metrics/AbcSize: Enabled: false + +Style/TrailingCommaInArrayLiteral: + Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 2334e7b..f5615aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..6be926d --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -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"). diff --git a/Gemfile b/Gemfile index 16ca910..af593b1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" gemspec @@ -13,4 +15,5 @@ end group :development, :test do gem "pry" + gem "rake", "~> 13.0" end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cca7175 --- /dev/null +++ b/Rakefile @@ -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] diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..7fa4fcc --- /dev/null +++ b/bin/console @@ -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__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -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 diff --git a/lib/retriable.rb b/lib/retriable.rb index 8442bff..2e99dfa 100644 --- a/lib/retriable.rb +++ b/lib/retriable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "timeout" require_relative "retriable/config" require_relative "retriable/exponential_backoff" @@ -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) @@ -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 diff --git a/lib/retriable/config.rb b/lib/retriable/config.rb index 38368be..738c837 100644 --- a/lib/retriable/config.rb +++ b/lib/retriable/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "exponential_backoff" module Retriable @@ -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 diff --git a/lib/retriable/core_ext/kernel.rb b/lib/retriable/core_ext/kernel.rb index a95c9f2..78e8e1b 100644 --- a/lib/retriable/core_ext/kernel.rb +++ b/lib/retriable/core_ext/kernel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../../retriable" module Kernel diff --git a/lib/retriable/exponential_backoff.rb b/lib/retriable/exponential_backoff.rb index a85af41..0dcdb80 100644 --- a/lib/retriable/exponential_backoff.rb +++ b/lib/retriable/exponential_backoff.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Retriable class ExponentialBackoff ATTRIBUTES = [ diff --git a/lib/retriable/version.rb b/lib/retriable/version.rb index 3a1ce99..ff9ec36 100644 --- a/lib/retriable/version.rb +++ b/lib/retriable/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Retriable - VERSION = "3.2.0".freeze + VERSION = "3.2.0" end diff --git a/retriable.gemspec b/retriable.gemspec index eaaa1fe..82f5c66 100644 --- a/retriable.gemspec +++ b/retriable.gemspec @@ -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" diff --git a/sig/retriable.rbs b/sig/retriable.rbs new file mode 100644 index 0000000..aa6582a --- /dev/null +++ b/sig/retriable.rbs @@ -0,0 +1,4 @@ +module Retriable + VERSION: String + # See the writing guide of rbs: https://github.com/ruby/rbs#guides +end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 53fcb48..42caf82 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Retriable::Config do let(:default_config) { described_class.new } diff --git a/spec/exponential_backoff_spec.rb b/spec/exponential_backoff_spec.rb index a0c0d8b..6bf7a41 100644 --- a/spec/exponential_backoff_spec.rb +++ b/spec/exponential_backoff_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Retriable::ExponentialBackoff do context "defaults" do let(:backoff_config) { described_class.new } diff --git a/spec/retriable_spec.rb b/spec/retriable_spec.rb index 02585ac..1001780 100644 --- a/spec/retriable_spec.rb +++ b/spec/retriable_spec.rb @@ -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 } @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 335d435..e028e6b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/exceptions.rb b/spec/support/exceptions.rb index 17e896c..744660b 100644 --- a/spec/support/exceptions.rb +++ b/spec/support/exceptions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class NonStandardError < Exception; end class SecondNonStandardError < NonStandardError; end class DifferentError < Exception; end