Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Gem::Source#fetch_spec
fetch_spec(name_tuple)
lib/rubygems/source.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/source.rb, line 126
def fetch_spec(name_tuple)
fetcher = Gem::RemoteFetcher.fetcher
spec_file_name = name_tuple.spec_name
# The name tuple comes from a remote index and is not otherwise
# validated, so refuse anything that would escape the spec cache
# directory when used as a path component.
if File.basename(spec_file_name) != spec_file_name
raise Gem::Exception, "malformed spec name: #{spec_file_name.inspect}"
end
source_uri = enforce_trailing_slash(uri) + "#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}"
cache_dir = cache_dir source_uri
local_spec = File.join cache_dir, spec_file_name
if File.exist? local_spec
spec = Gem.read_binary local_spec
Gem.load_safe_marshal
spec = begin
Gem::SafeMarshal.safe_load(spec)
rescue StandardError
nil
end
return spec if spec
end
source_uri.path << ".rz"
spec = fetcher.fetch_path source_uri
spec = Gem::Util.inflate spec
if update_cache?
require "fileutils"
FileUtils.mkdir_p cache_dir
File.open local_spec, "wb" do |io|
io.write spec
end
end
Gem.load_safe_marshal
# TODO: Investigate setting Gem::Specification#loaded_from to a URI
Gem::SafeMarshal.safe_load spec
end
Fetches a specification for the given Gem::NameTuple.
See also
#enforce_trailing_slash
#latest_platform_key
#download
#load_compact_index_specs
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0