patreon-ruby icon indicating copy to clipboard operation
patreon-ruby copied to clipboard

API v2

Open maximeCony opened this issue 4 years ago • 5 comments

Update Ruby lib to APIv2.

The generation code lives in https://github.com/Patreon/patreon_py/pull/18680

Note to reviewer

It should be easier to look at each commit individually.

Inspiration: https://github.com/Patreon/patreon-python/pull/28

maximeCony avatar Apr 27 '20 23:04 maximeCony

Although this Enum utility comes from an external source, I'm also not convinced that const_missing is the right way to implement enums.

The instance-variant of const_missing, which is the much more popular method_missing, has a companion method called Object#respond_to_missing?. It's meant to act as a fallback for respond_to?. There's no exact const-variant of respond_to_missing?, but one way to work around it is to turn this model inside out: instead of using const_missing to return a value for a constant that does not otherwise exist, use const_set to define a constant once. For enumerating all constants — something that methods like each, all, all_to_hash rely on — either the built-in Module#constants can serve that purpose, or, to keep them separate from other non-code-gen'd constants, we can maintain an array of @@enum_constants.

kourge avatar May 01 '20 20:05 kourge

Although this Enum utility comes from an external source, I'm also not convinced that const_missing is the right way to implement enums.

Do you think it is worth creating a separate PR to address that? Also wondering if there is a ruby gem that we could want to use.

maximeCony avatar May 01 '20 20:05 maximeCony

Yes, the author of that snippet has created a separate ruby-enum gem that does this right.

Edit: Yes, this can be addressed in another PR.

kourge avatar May 01 '20 21:05 kourge

I assume all changes to README.md here will also be ported over to its template source?

kourge avatar May 01 '20 21:05 kourge

I assume all changes to README.md here will also be ported over to its template source?

Yep! (Thanks for the reminder 😉)

maximeCony avatar May 01 '20 22:05 maximeCony