Skip to content

Commit

Permalink
Adds support for ruby 3.1.0 by fixing YAML
Browse files Browse the repository at this point in the history
If psych gem version is >= 4
* Replaces YAML loading positional arguments with keywords
* Replaces YAML.safe_load with YAML.load

Signed-off-by: Andrew Rempe <[email protected]>
  • Loading branch information
arempe93 committed Jan 7, 2022
1 parent 2812c3f commit dee255b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/global/backend/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ def get_config_by_key(config, key)
end

def load_yml_file(file)
YAML.safe_load(
ERB.new(IO.read(file)).result,
[Date, Time, DateTime, Symbol].concat(@yaml_whitelist_classes),
[], true
)
file_contents = ERB.new(IO.read(file)).result
permitted_classes = [Date, Time, DateTime, Symbol].concat(@yaml_whitelist_classes)

if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('4')
YAML.safe_load(file_contents, permitted_classes: permitted_classes, aliases: true)
else
YAML.safe_load(file_contents, permitted_classes, [], true)
end
end

def load_from_directory(path)
Expand Down

0 comments on commit dee255b

Please sign in to comment.