Skip to content

[Content Addressable Gems] Replace hash/array manipulation with named classes #9834

Description

@jenshenny

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 = 0INFO_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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions