summaryrefslogtreecommitdiff
path: root/lib/rubygems/config_file.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2023-04-18 09:51:06 +0900
committergit <svn-admin@ruby-lang.org>2023-04-19 06:56:21 +0000
commit644d7df021e17c70932da3173ec309ae1c8063d5 (patch)
tree8a352701847bc182417c8b6c7ed2298e91f722f5 /lib/rubygems/config_file.rb
parent45655089dac2f7ac5684f99607698d9eb6dae5d5 (diff)
[rubygems/rubygems] Introduce self.dump_with_rubygems_yaml
https://github.com/rubygems/rubygems/commit/3d3b0d80a1
Diffstat (limited to 'lib/rubygems/config_file.rb')
-rw-r--r--lib/rubygems/config_file.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb
index 029760286f..54b8842c6e 100644
--- a/lib/rubygems/config_file.rb
+++ b/lib/rubygems/config_file.rb
@@ -320,19 +320,13 @@ if you believe they were disclosed to a third party.
config = load_file(credentials_path).merge(host => api_key)
- config.transform_keys! do |k|
- k.is_a?(Symbol) ? ":#{k}" : k
- end
-
dirname = File.dirname credentials_path
require "fileutils"
FileUtils.mkdir_p(dirname)
- require "bundler/yaml_serializer"
-
permissions = 0o600 & (~File.umask)
File.open(credentials_path, "w", permissions) do |f|
- f.write Bundler::YAMLSerializer.dump(config)
+ f.write self.class.dump_with_rubygems_yaml(config)
end
load_api_keys # reload
@@ -492,12 +486,7 @@ if you believe they were disclosed to a third party.
yaml_hash[key.to_s] = value
end
- yaml_hash.transform_keys! do |k|
- k.is_a?(Symbol) ? ":#{k}" : k
- end
-
- require "bundler/yaml_serializer"
- Bundler::YAMLSerializer.dump(yaml_hash)
+ self.class.dump_with_rubygems_yaml(yaml_hash)
end
# Writes out this config file, replacing its source.
@@ -532,6 +521,15 @@ if you believe they were disclosed to a third party.
attr_reader :hash
protected :hash
+ def self.dump_with_rubygems_yaml(content)
+ content.transform_keys! do |k|
+ k.is_a?(Symbol) ? ":#{k}" : k
+ end
+
+ require "bundler/yaml_serializer"
+ Bundler::YAMLSerializer.dump(content)
+ end
+
def self.convert_rubygems_config_hash(content)
content.transform_keys! do |k|
if k.match?(/\A:(.*)\Z/)