grape
grape copied to clipboard
A mechanism to configure global before hooks
I am looking to implement query tags for activerecord when it's used inside a grape API class. One of the things I am looking into is a way to populate a context for the query tags callback inside the grape before callback.
It would be awesome if we could inject such callbacks into all Grape::API classes configuring them once. Sort of what Rails allows with their railties system.
Does subclassing Grape::API into MyGrape::API < Grape::API, using that everywhere and adding the hooks not work?
Does subclassing
Grape::APIintoMyGrape::API < Grape::API, using that everywhere and adding the hooks not work?
it does 👍 This is honestly a half baked idea but I was thinking we could have something "configured" globally. The use case is to be able to inject information into a global singleton like ActiveSupport::ExecutionContext that is inturn used by active record query log tags
I am not against it. Generally globals are useful when authoring libraries that can be composed, and I can definitely see the use case that you provided as a valid one - include gem 'grape-active-record-query-log-tags' to get query log tags in all your Grape APIs.