Skip to content

[REQ] [ruby] Reduce code duplication #22051

@Fryguy

Description

@Fryguy

Is your feature request related to a problem? Please describe.

The code generated under Ruby contains a significant amount of duplication. This duplication leads to code bloat both in file size and runtime memory usage.

I propose a base class for models, from which all models would inherit that would contain a lot of this shared logic.

@cliffano @zlx @autopp

Describe the solution you'd like

Initially, I'd like to introduce a new ApiModelBase class from which all base models would inherit. All models that have a parent would continue to inherit from their parent. In the initial PR introducing this new base model, I will move in all model methods that are static and that don't change per child class. This will set up the pattern after which follow up PRs can start moving other common methods and logic down to further eliminate duplication.

Describe alternatives you've considered

N/A

Additional context

I've started a PR to see how feasible it is, and I've created a draft PR in #22052.

I've also executed this against one of my gems and the file size dropped from 16MB to 12MB (25% reduction) even with only the small handful of common methods pulled out. See ManageIQ/kubevirt-sdk-ruby@master...Fryguy:kubevirt-sdk-ruby:reduce_gem_size

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions