Skip to content

Commit

Permalink
Version-lock rubocop and fix most failing cops
Browse files Browse the repository at this point in the history
As this gem supports all ruby versions >= 2.0, fix rubocop version to 0.50 (the last version supporting ruby 2.0).

Also fix all auto-correctable and/or superficial cops.

Remove `Gemfile.lock` from `.gitignore` (per kamui#94) and commit working lockfile.
  • Loading branch information
mvastola committed Dec 29, 2020
1 parent 9d3debc commit f0217e4
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 25 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.0

Style/StringLiterals:
EnforcedStyle: double_quotes

Expand Down
21 changes: 21 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-12-28 23:59:17 -0500 using RuboCop version 0.50.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 14

# Offense count: 2
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 202

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 15
5 changes: 4 additions & 1 deletion 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 @@ -8,7 +10,8 @@ group :test do
end

group :development do
gem "rubocop"
gem "rubocop", ">= 0.50", "< 0.51", require: false
gem "rubocop-rspec", "~> 1.18.0", require: false
end

group :development, :test do
Expand Down
76 changes: 76 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
PATH
remote: .
specs:
retriable (3.1.2)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.1)
coderay (1.1.3)
diff-lcs (1.4.4)
docile (1.3.4)
ffi (1.14.2)
listen (3.3.3)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
method_source (1.0.0)
parallel (1.20.1)
parser (2.7.2.0)
ast (~> 2.4.1)
powerpack (0.1.3)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
rainbow (2.2.2)
rake
rake (13.0.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.1)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.18.0)
rubocop (>= 0.50.0)
ruby-progressbar (1.10.1)
simplecov (0.20.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.2)
unicode-display_width (1.7.0)

PLATFORMS
ruby

DEPENDENCIES
bundler
listen (~> 3.1)
pry
retriable!
rspec
rubocop (>= 0.50, < 0.51)
rubocop-rspec (~> 1.18.0)
simplecov

BUNDLED WITH
2.1.4
4 changes: 2 additions & 2 deletions lib/retriable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def retriable(opts = {})
base_interval: base_interval,
multiplier: multiplier,
max_interval: max_interval,
rand_factor: rand_factor
rand_factor: rand_factor,
).intervals
end

Expand All @@ -59,7 +59,7 @@ def retriable(opts = {})
begin
return Timeout.timeout(timeout) { return yield(try) } if timeout
return yield(try)
rescue *[*exception_list] => exception
rescue *exception_list => exception
if on.is_a?(Hash)
raise unless exception_list.any? do |e|
exception.is_a?(e) && ([*on[e]].empty? || [*on[e]].any? { |pattern| exception.message =~ pattern })
Expand Down
18 changes: 9 additions & 9 deletions lib/retriable/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

module Retriable
class Config
ATTRIBUTES = (ExponentialBackoff::ATTRIBUTES + [
:sleep_disabled,
:max_elapsed_time,
:intervals,
:timeout,
:on,
:on_retry,
:contexts,
]).freeze
ATTRIBUTES = (ExponentialBackoff::ATTRIBUTES + %i[
sleep_disabled
max_elapsed_time
intervals
timeout
on
on_retry
contexts
]).freeze

attr_accessor(*ATTRIBUTES)

Expand Down
14 changes: 7 additions & 7 deletions lib/retriable/exponential_backoff.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Retriable
class ExponentialBackoff
ATTRIBUTES = [
:tries,
:base_interval,
:multiplier,
:max_interval,
:rand_factor,
].freeze
ATTRIBUTES = %i[
tries
base_interval
multiplier
max_interval
rand_factor
].freeze

attr_accessor(*ATTRIBUTES)

Expand Down
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

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "retriable/version"
Expand Down
8 changes: 4 additions & 4 deletions spec/exponential_backoff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
4.350816718580626,
5.339852157217869,
11.889873261212443,
18.756037881636484,
18.756037881636484
])
end

Expand All @@ -41,15 +41,15 @@
expect(described_class.new(base_interval: 1).intervals).to eq([
1.0488135024422882,
1.8227840477522461,
2.4812175837998227,
2.4812175837998227
])
end

it "generates intervals with a defined multiplier" do
expect(described_class.new(multiplier: 1).intervals).to eq([
0.5244067512211441,
0.607594682584082,
0.5513816852888495,
0.5513816852888495
])
end

Expand All @@ -61,7 +61,7 @@
expect(described_class.new(rand_factor: 0.2).intervals).to eq([
0.5097627004884576,
0.8145568095504492,
1.1712435167599646,
1.1712435167599646
])
end

Expand Down

0 comments on commit f0217e4

Please sign in to comment.