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

Add global callbacks to AASM compiler #1396

Merged
merged 2 commits into from
Feb 15, 2023

Conversation

mwudka
Copy link
Contributor

@mwudka mwudka commented Feb 14, 2023

Motivation

AASM state machines allow registering global callbacks like after_all_transitions, before_all_transactions, and so on. They accept a block that runs in the context of the record. The gem compiler creates these callbacks, but the block is of course bound to T.untyped. This requires the application code to always include a cast in global callback blocks.

Implementation

This change extends the AASM compiler to also generate the global callbacks (in addition to the event callbacks it already generates). Since the resulting methods are typed with blocks bound to the record class, the correct type appears in application code.

Tests

I updated the existing AASM spec to expect the global callbacks to be generated with the correct types.

AASM state machines allow registering global callbacks like
after_all_transitions, before_all_transactions, and so on. They accept a block
that runs in the context of the record. The gem compiler creates these
callbacks, but the block is of course bound to T.untyped, requiring a cast in
the application code. This change extends the AASM compiler to also generate
the global callbacks (in addition to the event callbacks it already generates).
Since the resulting methods are typed with blocks bound to the record class,
the correct type appears in application code.
@mwudka mwudka requested a review from a team as a code owner February 14, 2023 01:59
@paracycle paracycle merged commit 4c9b7a3 into Shopify:main Feb 15, 2023
@shopify-shipit shopify-shipit bot temporarily deployed to production February 21, 2023 12:01 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants