lib/rubocop/config_loader.rb in rubocop-0.24.1 vs lib/rubocop/config_loader.rb in rubocop-0.25.0

- old
+ new

@@ -1,17 +1,10 @@ # encoding: utf-8 require 'yaml' require 'pathname' -# Psych can give an error when reading an empty file, so we use syck in Ruby -# versions where it's available. Also, the problem with empty files does not -# appear in Ruby 2 or in JRuby 1.9 mode. -if RUBY_VERSION < '2.0.0' && RUBY_PLATFORM != 'java' - YAML::ENGINE.yamler = 'syck' -end - module RuboCop # This class represents the configuration of the RuboCop application # and all its cops. A Config is associated with a YAML configuration # file from which it was read. Several different Configs can be used # during a run of the rubocop program, if files in several @@ -29,10 +22,21 @@ alias_method :debug?, :debug alias_method :auto_gen_config?, :auto_gen_config def load_file(path) path = File.absolute_path(path) + + # Psych can give an error when reading an empty file, so we use syck in + # Ruby versions where it's available. Also, the problem with empty + # files does not appear in Ruby 2 or in JRuby 1.9 mode. + if RUBY_VERSION < '2.0.0' && RUBY_PLATFORM != 'java' + original_yamler = YAML::ENGINE.yamler + YAML::ENGINE.yamler = 'syck' + end hash = YAML.load_file(path) || {} + # Restore yamler for applications using RuboCop as a library. + YAML::ENGINE.yamler = original_yamler if original_yamler + puts "configuration from #{path}" if debug? resolve_inheritance(path, hash) Array(hash.delete('require')).each { |r| require(r) }