You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently iam working on a custom Railtie which wants to add a middleware to all mounted Grape::APIs in a Rails project in the Railties after_initialize block.
My first naive try was MyAPI.send(:insert_after, Rack::Head, MyMiddleware). It doesnt fail and MyAPI.middleware lists MyMiddleware but its not being called when requests come in. It just doesnt work.
So my understanding is that the mounted API is being instantiated before my addition runs and the change is not being picked up by the API.
Ive also experimented with MyAPI.compile! to kind of force a reload of the Grape API. This didnt succeed either. I have also realized that the instantiation process is not that easy to understand! Its quite complex.
Interesting. Update: I misunderstood the problem originally, updated my thoughts below.
Try calling MyAPI.compile, that returns and instance, while compile! ensures an instance on first call, but doesn't return it. Then insert_after on the result of compile?
If this doesn't work, put up a simple project that we can reproduce this in with a spec? Let's figure this out and document how to do this.
Activity
dblock commentedon Mar 22, 2021
Interesting. Update: I misunderstood the problem originally, updated my thoughts below.
Try calling
MyAPI.compile, that returns and instance, whilecompile!ensures an instance on first call, but doesn't return it. Theninsert_afteron the result ofcompile?If this doesn't work, put up a simple project that we can reproduce this in with a spec? Let's figure this out and document how to do this.
thedarkside commentedon Mar 22, 2021
Thank you for the reply!
Ive tested it in my project but it just raises:
The same with
.send.Ill put up a project in the next days as you suggest. Lets work on it!