spacex icon indicating copy to clipboard operation
spacex copied to clipboard

[Misc] Metaprogramming attempt

Open invacuo opened this issue 3 years ago • 4 comments

Description

Currently, we have to keep creating new classes for each endpoint that spacex api launches

These new classes are very similar to each other

This is an attempt to avoid the work to continue to write the main classes.

The work to support new endpoints will be limited to adding a new entry to this array of strings

While this undeniably comes with the downsides of metaprogramming, I am wondering if we can alleviate some of that pain by continuing to write the individual specs and updating the readme file.

invacuo avatar Oct 17 '21 01:10 invacuo

@rodolfobandeira When you get a chance, please look at the second commit in this PR. What are your thoughts?

invacuo avatar Oct 17 '21 01:10 invacuo

@rodolfobandeira When you get a chance, please look at the second commit in this PR. What are your thoughts?

@invacuo It make sense to me to start thinking about a better way to handle all this code duplication. The only concern is the flexibility per model adding custom attributes wherever is necessary but if we manage to get a good result there, I'm all for it! :)

rodolfobandeira avatar Oct 17 '21 04:10 rodolfobandeira

The only concern is the flexibility per model adding custom attributes wherever is necessary but if we manage to get a good result there, I'm all for it! :)

I think the easiest way to do it would be to skip adding the class names of the models that need the custom attribute to the KLASS_NAMES array and add the class manually like we currently do it.

There could be other ways like using class_eval but that will depend heavily on what kind of custom attributes we are trying to add.

invacuo avatar Oct 17 '21 05:10 invacuo

@rodolfobandeira Pushed a second commit that applies metaprogramming to legacy objects without custom properties defined. Curious to hear your thoughts.

invacuo avatar Oct 18 '21 00:10 invacuo