Context
In (ruby/rubygems#9773), there was a suggestion giving some of the hashes and arrays names — i.e. making concrete classes with names.
The branch has a lot of pre exisiting hash and array manipulation: positional rows indexed by magic constants, composite array keys, and parallel nested hashes threaded through long method chains. Two ideas to start:
1. Gem::CompactIndexClient::InfoRow
Compact index info rows are 5-element arrays indexed via INFO_NAME = 0 … INFO_REQS = 4. Wrap them in a Struct with named accessors (#version, #suffix, #ruby_requirement, #platform_requirement, #created_at) and convert at the consumption boundary via InfoRow.wrap, so older Bundler-shipped copies of the client (which return plain arrays behind the load guard) keep working. Parser hot path is unchanged; INFO_* constants stay for compatibility.
2. Gem::QueryUtils::VersionPlatforms
gem list/search/info build two parallel auto-vivifying hashes (platforms and platform_ruby_abis) and pass them together through six methods. Replace both with one presenter exposing #versions, #platforms_for(version), #ruby_abis_for(version, platform), and #ruby_abi_metadata?, dropping the paired parameters and the repeated values.any? { .values.any?(&:any?) } crawls.
There are more candidates (e.g. the throwaway row arrays and composite keys in Gem::Source#decode_content_addressable_tuples, the stub-target: hash in StubSpecification), which can follow the same pattern later.
Context
In (ruby/rubygems#9773), there was a suggestion giving some of the hashes and arrays names — i.e. making concrete classes with names.
The branch has a lot of pre exisiting hash and array manipulation: positional rows indexed by magic constants, composite array keys, and parallel nested hashes threaded through long method chains. Two ideas to start:
1.
Gem::CompactIndexClient::InfoRowCompact index info rows are 5-element arrays indexed via
INFO_NAME = 0…INFO_REQS = 4. Wrap them in a Struct with named accessors (#version,#suffix,#ruby_requirement,#platform_requirement,#created_at) and convert at the consumption boundary viaInfoRow.wrap, so older Bundler-shipped copies of the client (which return plain arrays behind the load guard) keep working. Parser hot path is unchanged;INFO_*constants stay for compatibility.2.
Gem::QueryUtils::VersionPlatformsgem list/search/infobuild two parallel auto-vivifying hashes (platformsandplatform_ruby_abis) and pass them together through six methods. Replace both with one presenter exposing#versions,#platforms_for(version),#ruby_abis_for(version, platform), and#ruby_abi_metadata?, dropping the paired parameters and the repeatedvalues.any? { .values.any?(&:any?) }crawls.There are more candidates (e.g. the throwaway row arrays and composite keys in
Gem::Source#decode_content_addressable_tuples, thestub-target:hash inStubSpecification), which can follow the same pattern later.