Skip to content

Commit bc3e13e

Browse files
Romuald Contyekohl
andcommitted
Fix puppet classes import filter when using Ruby >=3.1 and Regexp/Symbol in YAML file
Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>
1 parent 411bba7 commit bc3e13e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.rubocop_todo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-12-17 15:04:46 UTC using RuboCop version 1.23.0.
3+
# on 2024-12-17 15:06:35 UTC using RuboCop version 1.23.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -25,7 +25,7 @@ Metrics/BlockLength:
2525
# Offense count: 2
2626
# Configuration parameters: CountComments, CountAsOne.
2727
Metrics/ClassLength:
28-
Max: 246
28+
Max: 254
2929

3030
# Offense count: 19
3131
# Configuration parameters: IgnoredMethods.

app/services/foreman_puppet/puppet_class_importer.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,17 @@ def ignored_file_path
229229
end
230230

231231
def load_ignored_file
232-
File.exist?(ignored_file_path) ? YAML.load_file(ignored_file_path) : {}
232+
if File.exist?(ignored_file_path)
233+
# Ruby 3+
234+
if YAML.respond_to(:safe_load_file)
235+
YAML.safe_load_file(ignored_file_path, permitted_classes: [Symbol, Regexp])
236+
else
237+
# NOTE: Once we drop Ruby 2.7 support, you can drop the load_file call.
238+
YAML.load_file(ignored_file_path)
239+
end
240+
else
241+
{}
242+
end
233243
end
234244

235245
def ignored_file

0 commit comments

Comments
 (0)