top | item 46382928

(no title)

digitaltrees | 2 months ago

Ruby is amazing. I recently built a layer on top of Rails that can generate an API from a single markdown file. I did the same thing in python but it was much harder and JavaScript would have been a beast. Ruby can meta program like nothing else.

discuss

order

mierz00|2 months ago

Curious to hear more about this, do you have any examples?

digitaltrees|2 months ago

We might release it as a framework of gems.

We created an Abstract controller that handles all of the typical behavior for a resource, auth, filtering, pagination, tenancy, import/export, serialization etc.

Then we expanded rails generators to cover ALL typical behavior. And the markdown file calls the generators.

It was a bit complicated to model polymorphic behavior but we got it working thanks to Ruby/Rails.

But the basic premise that made this work is: Use only restful actions; don’t turn it into RPC. Recognize that most RPC/graphql functions are state changes that could have been a patch request. So instead of /clients/activate its /clients with a status attribute for “activate” or “archive”. Then most nested routes aren’t needed, use accepts nested attributes for and return child ids in the show action. There’s more to it that this but by strictly following conventions and modeling the data for rest, the api ends up Super simple.

Our standard controller only whitelists strong params. All other behavior is automatic.

tasuki|2 months ago

> Ruby can meta program like nothing else.

Have you heard about Lisp?

digitaltrees|2 months ago

(((((((Heard)))))))

I might have forgotten a (

Ruby is clean. Which I love.

cutler|2 months ago

Try Clojure. Macros make method_missing look primitive.

szundi|2 months ago

[deleted]