spacex
spacex copied to clipboard
[Misc] Metaprogramming attempt
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.
@rodolfobandeira When you get a chance, please look at the second commit in this PR. What are your thoughts?
@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! :)
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.
@rodolfobandeira Pushed a second commit that applies metaprogramming to legacy objects without custom properties defined. Curious to hear your thoughts.