Skip to content

Commit 018b71d

Browse files
authored
v0.13.0 Release: Ruby Version Upgrade Part #1 (#71)
* Ruby version upgrade to v3.1
1 parent 79d40c4 commit 018b71d

File tree

11 files changed

+34
-27
lines changed

11 files changed

+34
-27
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
ruby: ['2.5', '2.6', '2.7']
10+
ruby: ['3.1','3.2','3.3']
1111
name: Test ruby v${{ matrix.ruby }} support
1212
steps:
1313
- uses: actions/checkout@v1
@@ -17,7 +17,7 @@ jobs:
1717
ruby-version: ${{ matrix.ruby }}
1818
- name: Build with dependencies
1919
run: |
20-
gem install bundler -v 2.1
20+
gem install bundler -v 2.5.14
2121
bundle install
2222
- name: Test with rspec
2323
run: |

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AllCops:
2-
TargetRubyVersion: 2.4
2+
TargetRubyVersion: 3.1
33

44
Style/Documentation:
55
Enabled: false

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ruby:2.5-alpine
1+
FROM ruby:3.1
22

33
RUN mkdir -p /usr/src/app
44
WORKDIR /usr/src/app

lib/vrt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def all_matching_categories(categories)
8181
def find_node(vrt_id:, preferred_version: nil, max_depth: 'variant', version: nil) # rubocop:disable Lint/UnusedMethodArgument
8282
new_version = preferred_version || current_version
8383
if get_map(version: new_version).valid?(vrt_id)
84-
get_map(version: new_version).find_node(vrt_id, max_depth: max_depth)
84+
get_map(version: new_version).find_node(vrt_id, max_depth:)
8585
elsif deprecated_node?(vrt_id)
8686
find_deprecated_node(vrt_id, preferred_version, max_depth)
8787
else

lib/vrt/cross_version_mapping.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def latest_version_for_deprecated_node(vrt_id)
3232
def find_deprecated_node(vrt_id, new_version = nil, max_depth = 'variant')
3333
version = latest_version_for_deprecated_node(vrt_id)
3434
node_id = deprecated_node_json[vrt_id][new_version] || deprecated_node_json[vrt_id][version]
35-
new_node = VRT::Map.new(new_version).find_node(node_id, max_depth: max_depth)
35+
new_node = VRT::Map.new(new_version).find_node(node_id, max_depth:)
3636
new_node.nil? ? find_deprecated_node(node_id, new_version, max_depth) : new_node
3737
end
3838

3939
def find_valid_parent_node(vrt_id, new_version, max_depth)
4040
new_map = VRT::Map.new(new_version)
4141
if new_map.valid?(vrt_id)
42-
new_map.find_node(vrt_id, max_depth: max_depth)
42+
new_map.find_node(vrt_id, max_depth:)
4343
else
4444
parent = vrt_id.split('.')[0..-2].join('.')
4545
return nil if parent.empty?

lib/vrt/map.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(version = nil)
1818
end
1919

2020
def find_node(string, max_depth: 'variant')
21-
@_found_nodes[string + max_depth] ||= walk_node_tree(string, max_depth: max_depth)
21+
@_found_nodes[string + max_depth] ||= walk_node_tree(string, max_depth:)
2222
end
2323

2424
def valid?(vrt_id)
@@ -52,7 +52,7 @@ def construct_lineage(string, max_depth)
5252
return unless valid_identifier?(string)
5353

5454
lineage = ''
55-
walk_node_tree(string, max_depth: max_depth) do |ids, node, level|
55+
walk_node_tree(string, max_depth:) do |ids, node, level|
5656
return unless node
5757

5858
lineage += node.name

lib/vrt/mapping.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def initialize(scheme, subdirectory = nil)
1313
# returns the most specific value provided in the mapping file for the given vrt id
1414
#
1515
# if no mapping file exists for the given version, the mapping file for the earliest version available will be used
16+
# rubocop:disable Metrics/CyclomaticComplexity
17+
# rubocop:disable Metrics/PerceivedComplexity
1618
def get(id_list, version)
1719
# update the vrt id to the first version we have a mapping file for
1820
unless @mappings.key?(version)
@@ -29,15 +31,17 @@ def get(id_list, version)
2931
# { remediation_advice: { remediation_advice: '...', references: [...] } }
3032
keys.each_with_object({}) do |key, acc|
3133
acc[key.to_sym] = get_key(
32-
id_list: id_list,
33-
mapping: mapping,
34-
key: key
34+
id_list:,
35+
mapping:,
36+
key:
3537
) || default&.dig(key)
3638
end
3739
else
38-
get_key(id_list: id_list, mapping: mapping, key: @scheme) || default
40+
get_key(id_list:, mapping:, key: @scheme) || default
3941
end
4042
end
43+
# rubocop:enable Metrics/CyclomaticComplexity
44+
# rubocop:enable Metrics/PerceivedComplexity
4145

4246
private
4347

@@ -74,7 +78,7 @@ def key_by_id(mapping)
7478
if mapping.is_a?(Array) && mapping.first.is_a?(Hash) && mapping.first.key?('id')
7579
mapping.each_with_object({}) { |entry, acc| acc[entry['id'].to_sym] = key_by_id(entry) }
7680
elsif mapping.is_a?(Hash)
77-
mapping.each_with_object({}) { |(key, value), acc| acc[key] = key_by_id(value) }
81+
mapping.transform_values { |value| key_by_id(value) }
7882
else
7983
mapping
8084
end

lib/vrt/node.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def construct_vrt_id
2424
end
2525

2626
def mappings
27-
Hash[VRT.mappings.map { |name, map| [name, map.get(id_list, @version)] }]
27+
VRT.mappings.transform_values { |map| map.get(id_list, @version) }
2828
end
2929

3030
def third_party_links
31-
Hash[VRT.third_party_links.map { |name, map| [name, map.get(id_list, @version)] }]
31+
VRT.third_party_links.transform_values { |map| map.get(id_list, @version) }
3232
end
3333

3434
def id_list

lib/vrt/third_party_links.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def load_mappings
2727

2828
# For flat third party links ther is no hierarchical step up
2929
def get_key(id_list:, mapping:, key: nil) # rubocop:disable Lint/UnusedMethodArgument
30-
mapping.dig(id_list.join('.'))
30+
mapping[id_list.join('.')]
3131
end
3232
end
3333
end

spec/vrt_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
describe '#find_node' do
7070
subject(:found_node) do
7171
described_class.find_node(
72-
vrt_id: vrt_id,
72+
vrt_id:,
7373
preferred_version: new_version,
74-
max_depth: max_depth
74+
max_depth:
7575
)
7676
end
7777

0 commit comments

Comments
 (0)