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

Kaminari #2100

Closed
wants to merge 2 commits into from
Closed

Kaminari #2100

wants to merge 2 commits into from

Conversation

rzane
Copy link
Contributor

@rzane rzane commented Nov 28, 2024

Motivation

Kaminari is one of the most popular gems in the Rails ecosystem.

Kaminari's .page scope is defined dynamically and not detected by Tapioca's scopes compiler. Also, .page uses .extending to extend the relation with more methods (e.g. .per, .total_count, .total_pages, .current_page).

See issue #1859 for more details.

Implementation

This PR adds a compiler for Kaminari that adds the .page method to GeneratedRelationMethods. The return type is a union:

T.all(PrivateRelation, Kaminari::PageScopeMethods, Kaminari::ActiveRecordRelationMethods)

If the ActiveRecordRelations compiler is not enabled, this compiler will take that into account.

Tests

Tests are included.

@rzane rzane requested a review from a team as a code owner November 28, 2024 16:34
@KaanOzkan
Copy link
Contributor

I think we want to reduce the number of external gem compilers in tapioca. So ideally this would live inside Kaminari repo and be maintained by the gem maintainers. I also remember https://github.com/angellist/boba which aimed to host tapioca compilers. cc @stathis-alexander

@stathis-alexander
Copy link
Contributor

stathis-alexander commented Nov 28, 2024

I think we want to reduce the number of external gem compilers in tapioca. So ideally this would live inside Kaminari repo and be maintained by the gem maintainers.

The idea of gem maintainers hosting their own compilers is a nice future to look forward to!

I also remember https://github.com/angellist/boba which aimed to host tapioca compilers. cc @stathis-alexander

We'd be happy to accept this as part of Boba. We don't use Kaminari (we use graphql), but it fits the concept of the Boba
gem perfectly. We also host compilers for other common gems / DSLs: AttrJson, Paperclip, MoneyRails, etc.

@rzane
Copy link
Contributor Author

rzane commented Nov 28, 2024

Thanks all, I totally missed this note at the bottom of the README: https://github.com/Shopify/tapioca?tab=readme-ov-file#dsl-compilers.

I'll send a PR over to Boba soon.

@rzane rzane closed this Nov 28, 2024
@rzane rzane deleted the kaminari branch November 28, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants