Skip to content

Commit

Permalink
Add ruby 3.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSouthan committed Jan 23, 2025
1 parent 1f6cc19 commit fd4bc8c
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
validate:
strategy:
matrix:
ruby-version: ["2.7", "3.0", "3.1", "3.2"]
ruby-version: ["3.1", "3.2", "3.3", "3.4"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
50 changes: 2 additions & 48 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,8 @@
inherit_from: .rubocop_todo.yml

inherit_gem:
gc_ruboconfig: rubocop.yml
require: rubocop-rails

AllCops:
TargetRubyVersion: 3.2

# Limit lines to 90 characters.
Layout/LineLength:
Max: 90

Metrics/ClassLength:
Max: 400

# Avoid single-line methods.
Style/SingleLineMethods:
AllowIfMethodIsEmpty: true

# Wants underscores in all large numbers. Pain in the ass for things like
# unix timestamps.
Style/NumericLiterals:
Enabled: false

# Wants you to use the same argument names for every reduce. This seems kinda
# naff compared to naming them semantically
Style/SingleLineBlockParams:
Enabled: false

Style/SignalException:
EnforcedStyle: 'only_raise'

# Wants to exclude accents from comments
Style/AsciiComments:
Enabled: false

# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 25

# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 400

Layout/DotPosition:
EnforcedStyle: 'trailing'

# Wants to to lock to Ruby 2.4 as specified here but as this is a public gem
# this is quite aggressive.
Gemspec/RequiredRubyVersion:
Enabled: false

Rails/Blank:
Enabled: false
NewCops: enable
62 changes: 27 additions & 35 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,69 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-08-25 10:15:35 UTC using RuboCop version 0.89.1.
# on 2025-01-23 15:25:02 UTC using RuboCop version 1.71.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: 8
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 25

# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 8
# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'ibandit.gemspec'

# Offense count: 1
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
# Configuration parameters: LengthThreshold.
Metrics/CollectionLiteralLength:
Exclude:
- 'lib/ibandit/sweden/bank_lookup.rb'
- 'lib/ibandit/german_details_converter.rb'

# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'lib/ibandit/german_details_converter.rb'

# Offense count: 1
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/ibandit/structure_spec.rb'

# Offense count: 1
# Configuration parameters: Max.
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Exclude:
- 'spec/ibandit/iban_spec.rb'
Max: 6

# Offense count: 1
RSpec/ExpectInHook:
Exclude:
- 'spec/ibandit/german_details_converter_spec.rb'

# Offense count: 12
# Offense count: 15
RSpec/MultipleExpectations:
Max: 2

# Offense count: 182
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 7

# Offense count: 20
# Configuration parameters: IgnoreSharedExamples.
# Offense count: 26
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/ibandit/iban_spec.rb'

# Offense count: 368
# Offense count: 177
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 6

# Offense count: 18
RSpec/ScatteredSetup:
Exclude:
- 'spec/ibandit/iban_assembler_spec.rb'
- 'spec/ibandit/iban_spec.rb'
Max: 5

# Offense count: 13
# Offense count: 37
RSpec/SubjectStub:
Exclude:
- 'spec/ibandit/iban_spec.rb'
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.4.1
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 1.22.0 - January 22, 2025

- Remove support for Ruby < 3.1, add support for Ruby >= 3.4
- Update BLZ2 data - BLZ_20241209
- Update IBAN structures for `BE`, `ES`, `XK`.
- Add partial support for `SO`, `NI`, `FK`, `OM`, `YE` IBANs.

Expand Down
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
source 'https://rubygems.org'

gemspec

group :development, :test do
gem "gc_ruboconfig", "~> 5.0"
gem "nokogiri", "~> 1.6"
gem "pry", "~> 0.13"
gem "pry-byebug", "~> 3.10"
gem "rspec", "~> 3.12"
gem "rspec-its", "~> 1.2"
gem "sax-machine", "~> 1.3"
end
9 changes: 1 addition & 8 deletions ibandit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.7.0"
spec.add_development_dependency "gc_ruboconfig", "~> 5.0"
spec.add_development_dependency "nokogiri", "~> 1.6"
spec.add_development_dependency "pry", "~> 0.13"
spec.add_development_dependency "pry-byebug", "~> 3.10"
spec.add_development_dependency "rspec", "~> 3.12"
spec.add_development_dependency "rspec-its", "~> 1.2"
spec.add_development_dependency "sax-machine", "~> 1.3"

spec.add_runtime_dependency "i18n"
spec.add_dependency "i18n"
end
6 changes: 2 additions & 4 deletions lib/ibandit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ def find_bic(country_code, national_id)
end

def structures
@structures ||= YAML.safe_load(
File.read(File.expand_path("../data/structures.yml", __dir__)),
permitted_classes: [Range, Symbol],
)
@structures ||= YAML.safe_load_file(File.expand_path("../data/structures.yml", __dir__),
permitted_classes: [Range, Symbol])
end

def translate(key, options = {})
Expand Down
20 changes: 8 additions & 12 deletions lib/ibandit/iban.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,15 @@ def valid_branch_code_length?
return unless valid_country_code?
return true if swift_branch_code.to_s.length == structure[:branch_code_length]

if structure[:branch_code_length]&.zero?
@errors[:branch_code] = Ibandit.translate(:not_used_in_country,
@errors[:branch_code] = if structure[:branch_code_length]&.zero?
Ibandit.translate(:not_used_in_country,
country_code: country_code)
elsif swift_branch_code.nil? || swift_branch_code.empty?
@errors[:branch_code] = Ibandit.translate(:is_required)
else
@errors[:branch_code] =
Ibandit.translate(:wrong_length,
expected: structure[:branch_code_length])
end
elsif swift_branch_code.nil? || swift_branch_code.empty?
Ibandit.translate(:is_required)
else
Ibandit.translate(:wrong_length,
expected: structure[:branch_code_length])
end
false
end

Expand Down Expand Up @@ -390,7 +389,6 @@ def valid_australian_details?
valid_modulus_check_branch_code?
end

# rubocop:disable Metrics/AbcSize
def bank_code_passes_checksum_test?
return false unless swift_bank_code
return false if swift_bank_code.length != 9
Expand All @@ -407,8 +405,6 @@ def bank_code_passes_checksum_test?

mod.zero?
end
# rubocop:enable Metrics/AbcSize

###################
# Private methods #
###################
Expand Down
2 changes: 1 addition & 1 deletion lib/ibandit/sweden/bank_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.for_bank_code(bank_code)
end

def self.bank_info_table
@swedish_bank_lookup ||=
@bank_info_table ||=
begin
relative_path = "../../../../data/raw/swedish_bank_lookup.yml"
raw_info = YAML.load_file(File.expand_path(relative_path, __FILE__))
Expand Down
48 changes: 26 additions & 22 deletions spec/ibandit/iban_assembler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@
it_behaves_like "allows round trips", "ES80 2310 0001 1800 0001 2345"

context "without a bank_code or branch code" do
before { args.delete(:bank_code) }

before { args.delete(:branch_code) }

before { args[:account_number] = "23100001180000012345" }
before do
args.delete(:bank_code)
args.delete(:branch_code)
args[:account_number] = "23100001180000012345"
end

it { is_expected.to be_nil }
end
Expand Down Expand Up @@ -487,27 +487,29 @@
it_behaves_like "allows round trips", "HU42 1177 3016 1111 1018 0000 0000"

context "without a bank_code or branch_code" do
before { args.delete(:bank_code) }

before { args.delete(:branch_code) }

before { args[:account_number] = "11773016-11111018-00000000" }
before do
args.delete(:bank_code)
args.delete(:branch_code)
args[:account_number] = "11773016-11111018-00000000"
end

it { is_expected.to be_nil }
end

context "without a bank_code" do
before { args.delete(:bank_code) }

before { args[:account_number] = "11773016-11111018-00000000" }
before do
args.delete(:bank_code)
args[:account_number] = "11773016-11111018-00000000"
end

it { is_expected.to be_nil }
end

context "without a branch_code" do
before { args.delete(:branch_code) }

before { args[:account_number] = "11773016-11111018-00000000" }
before do
args.delete(:branch_code)
args[:account_number] = "11773016-11111018-00000000"
end

it { is_expected.to be_nil }
end
Expand Down Expand Up @@ -826,9 +828,10 @@
it_behaves_like "allows round trips", "NO93 8601 1117 947"

context "without a bank_code" do
before { args.delete(:bank_code) }

before { args[:account_number] = "86011117947" }
before do
args.delete(:bank_code)
args[:account_number] = "86011117947"
end

it { is_expected.to be_nil }
end
Expand All @@ -854,9 +857,10 @@
it_behaves_like "allows round trips", "PL60 1020 1026 0000 0422 7020 1111"

context "without a bank_code" do
before { args.delete(:bank_code) }

before { args[:account_number] = "60102010260000042270201111" }
before do
args.delete(:bank_code)
args[:account_number] = "60102010260000042270201111"
end

it { is_expected.to be_nil }
end
Expand Down
Loading

0 comments on commit fd4bc8c

Please sign in to comment.