diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-06-09 21:48:31 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-06-09 21:48:56 +0530 |
commit | 8b749ee85b04307135d368f05275d50e6cbf76a0 (patch) | |
tree | 442aba2aa070ae5b6de3b2948bb32e265b06f4fb | |
parent | f684a6d9d184b9acb9a12fb1009d4c1a18db71ac (diff) | |
download | bundler-8b749ee85b04307135d368f05275d50e6cbf76a0.tar.gz |
Shifted Settings to use the YAMLSerializer
-rw-r--r-- | lib/bundler/settings.rb | 24 | ||||
-rw-r--r-- | lib/bundler/yaml_serializer.rb | 10 |
2 files changed, 13 insertions, 21 deletions
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index de0644adce..72d37a8913 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -201,21 +201,14 @@ module Bundler hash.delete(key) if value.nil? SharedHelpers.filesystem_access(file) do |p| FileUtils.mkdir_p(p.dirname) - p.open("w") {|f| f.write(serialize_hash(hash)) } + require "bundler/yaml_serializer" + p.open("w") {|f| f.write(YAMLSerializer.dump(hash)) } end end value end - def serialize_hash(hash) - yaml = String.new("---\n") - hash.each do |key, value| - yaml << key << ": " << value.to_s.gsub(/\s+/, " ").inspect << "\n" - end - yaml - end - def global_config_file if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty? Pathname.new(ENV["BUNDLE_CONFIG"]) @@ -246,20 +239,11 @@ module Bundler SharedHelpers.filesystem_access(config_file, :read) do valid_file = config_file && config_file.exist? && !config_file.size.zero? return {} if ignore_config? || !valid_file - config_pairs = config_file.read.scan(CONFIG_REGEX).map do |m| - key, _, value = m - [convert_to_backward_compatible_key(key), value.gsub(/\s+/, " ").tr('"', "'")] - end - Hash[config_pairs] + require "bundler/yaml_serializer" + YAMLSerializer.load config_file.read end end - def convert_to_backward_compatible_key(key) - key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z} - key = key.gsub(".", "__") if key.include?(".") - key - end - # TODO: duplicates Rubygems#normalize_uri # TODO: is this the correct place to validate mirror URIs? def self.normalize_uri(uri) diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 015fd17c6f..327baa4ee7 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -40,6 +40,7 @@ module Bundler res = {} stack = [res] str.scan(SCAN_REGEX).each do |(indent, key, _, val)| + key = convert_to_backward_compatible_key(key) depth = indent.scan(/ /).length if val.empty? new_hash = {} @@ -52,8 +53,15 @@ module Bundler res end + # for settings' keys + def convert_to_backward_compatible_key(key) + key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z} + key = key.gsub(".", "__") if key.include?(".") + key + end + class << self - private :dump_hash + private :dump_hash, :convert_to_backward_compatible_key end end end |