Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Gem::ConfigFile#set_api_key
set_api_key(host, api_key)
lib/rubygems/config_file.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/config_file.rb, line 481
def set_api_key(host, api_key)
if credential_store && host != :rubygems_api_key
store = active_credential_store
if api_key.to_s.empty?
delete_stored_key(store, host)
elsif store&.set(self.class.credential_store_account(host), api_key)
remove_api_key_from_file(host)
return
else
delete_stored_key(store, host)
warn_credential_store_fallback
end
end
check_credentials_permissions
config = load_file(credentials_path).merge(self.class.normalize_credentials_key(host) => api_key)
write_credentials(config)
load_api_keys # reload
end
Set a specific host’s API key to api_key
See also
#rubygems_api_key=
#set_config_file_name
#rubygems_api_key
#state_file_name
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0