Skip to content

Commit 92d14eb

Browse files
authored
Merge pull request #402 from DannyBen/refactor/yaml-loader
Simplify YAML loading
2 parents a9287a9 + 558247e commit 92d14eb

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

lib/bashly/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Config
1010

1111
def self.new(config)
1212
if config.is_a? String
13-
YAML.properly_load_file(config).compose
13+
YAML.load_file(config).compose
1414
else
1515
config
1616
end

lib/bashly/extensions/yaml.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module YAML
2-
# This awkward patch is due to https://bugs.ruby-lang.org/issues/17866
3-
def self.properly_load_file(path)
4-
YAML.load_file path, aliases: true
5-
rescue ArgumentError
6-
# :nocov:
7-
YAML.load_file path
8-
# :nocov:
2+
# We trust our loaded YAMLs
3+
# This patch is due to https://bugs.ruby-lang.org/issues/17866
4+
# StackOverflow: https://stackoverflow.com/questions/71191685/visit-psych-nodes-alias-unknown-alias-default-psychbadalias/71192990#71192990
5+
class << self
6+
alias load unsafe_load
97
end
108
end

lib/bashly/library_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def git?
1414
end
1515

1616
def config
17-
@config ||= YAML.properly_load_file config_path
17+
@config ||= YAML.load_file config_path
1818
end
1919

2020
def libraries

lib/bashly/message_strings.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def values
1313
private
1414

1515
def values!
16-
defaults = YAML.properly_load_file asset('libraries/strings/strings.yml')
16+
defaults = YAML.load_file asset('libraries/strings/strings.yml')
1717
defaults.merge project_strings
1818
end
1919

@@ -23,7 +23,7 @@ def project_strings
2323

2424
def project_strings!
2525
if File.exist? project_strings_path
26-
YAML.properly_load_file project_strings_path
26+
YAML.load_file project_strings_path
2727
else
2828
{}
2929
end

lib/bashly/refinements/compose_refinements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def compose(keyword = 'import')
2222
end
2323

2424
def safe_load_yaml(path)
25-
loaded = YAML.properly_load_file path
25+
loaded = YAML.load_file path
2626
return loaded if loaded.is_a?(Array) || loaded.is_a?(Hash)
2727

2828
raise Bashly::ConfigurationError, "Cannot find a valid YAML in g`#{path}`"

spec/spec_mixin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def reset_tmp_dir(create_src: false, init: false, example: nil)
99

1010
def load_fixture(filename)
1111
@loaded_fixtures ||= {}
12-
@loaded_fixtures[filename] ||= YAML.properly_load_file "spec/fixtures/#{filename}.yml"
12+
@loaded_fixtures[filename] ||= YAML.load_file "spec/fixtures/#{filename}.yml"
1313
end
1414

1515
def cp(source, target = 'spec/tmp/')

0 commit comments

Comments
 (0)