diff --git a/src/onecfg/lib/config/type/yaml.rb b/src/onecfg/lib/config/type/yaml.rb index a295f9d5fa..a4acbd9e87 100644 --- a/src/onecfg/lib/config/type/yaml.rb +++ b/src/onecfg/lib/config/type/yaml.rb @@ -41,7 +41,15 @@ module OneCfg::Config::Type def load(name = @name) reset - @content = YAML.load_file(name) + if Gem::Version.new(Psych.const_get(:VERSION)) >= Gem::Version.new('4.0') + @content = YAML.load_file(name, :aliases => true) + + # for backward compatibility with older Psych return `false` + # instead of `nil` if the file was empty + @content = false if @content.nil? + else + @content = YAML.load_file(name) + end @content end diff --git a/src/onecfg/lib/patch/apply.rb b/src/onecfg/lib/patch/apply.rb index 8984978736..771784ced4 100644 --- a/src/onecfg/lib/patch/apply.rb +++ b/src/onecfg/lib/patch/apply.rb @@ -165,7 +165,11 @@ module OneCfg::Patch # # @param filename [String] path to patch in YAML format def parse_yaml(filename) - @patches = YAML.load_file(filename) + if Psych::VERSION > '4.0' + @patches = YAML.load_file(filename, :aliases => true) + else + @patches = YAML.load_file(filename) + end return if @patches.is_a?(Hash) diff --git a/src/onecfg/lib/settings.rb b/src/onecfg/lib/settings.rb index 97d716a3b4..c445e536f5 100644 --- a/src/onecfg/lib/settings.rb +++ b/src/onecfg/lib/settings.rb @@ -42,7 +42,11 @@ module OneCfg reset if ::File.exist?(@name) - @content = YAML.load_file(@name) + if Psych::VERSION > '4.0' + @content = YAML.load_file(@name, :aliases => true) + else + @content = YAML.load_file(@name) + end end rescue StandardError => e OneCfg::LOG.error("Can't load settings from '#{@name}' " \