Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A mechanism to configure global before hooks #2522

Open
dhruvCW opened this issue Jan 15, 2025 · 3 comments
Open

A mechanism to configure global before hooks #2522

dhruvCW opened this issue Jan 15, 2025 · 3 comments

Comments

@dhruvCW
Copy link
Contributor

dhruvCW commented Jan 15, 2025

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.

@dblock
Copy link
Member

dblock commented Jan 15, 2025

Does subclassing Grape::API into MyGrape::API < Grape::API, using that everywhere and adding the hooks not work?

@dhruvCW
Copy link
Contributor Author

dhruvCW commented Jan 16, 2025

Does subclassing Grape::API into MyGrape::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

@dblock
Copy link
Member

dblock commented Jan 16, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants