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

Update AASM DSL generator #786

Merged
merged 1 commit into from
Feb 14, 2022

Conversation

davebenvenuti
Copy link
Contributor

@davebenvenuti davebenvenuti commented Feb 2, 2022

Motivation

Hello! I encountered some type errors in a project related to the AASM gem. More specifically, it appears the DSL generator for AASM only supports one form of their lifecycle callbacks.

class Foo
  include AASM
  
  aasm do
    state :state1
    state :state2

    event :do_something do
      transitions from: :state1, to: :state2

      after :some_method
    end

    def some_method
    end
  end
end

The above code would produce a typeerror along the lines of after requires a block parameter, but no block was passed https://srb.help/7021. However, this is in fact valid usage of the after hook. Similar to ActiveRecord callbacks, they accept either a block or a symbol corresponding to a method name.

Implementation

This PR updates the generated sigs for AASM lifecycle hooks from this:

sig { params(block: T.proc.bind(StateMachine).void).returns(T.untyped)  }

To this:

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }  }

Tests

I updated the relevant test.

Copy link
Contributor

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks legit to me

@paracycle paracycle force-pushed the aasm-lifecycle-callbacks-accept-optional-symbol branch from cdd00b4 to 8620e9a Compare February 14, 2022 20:56
@paracycle paracycle force-pushed the aasm-lifecycle-callbacks-accept-optional-symbol branch from 8620e9a to 5ebf941 Compare February 14, 2022 22:34
@paracycle paracycle enabled auto-merge February 14, 2022 22:35
@paracycle paracycle merged commit 477d509 into main Feb 14, 2022
@paracycle paracycle deleted the aasm-lifecycle-callbacks-accept-optional-symbol branch February 14, 2022 22:44
@shopify-shipit shopify-shipit bot temporarily deployed to production February 17, 2022 22:56 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to 0-7-stable March 29, 2022 19:23 Inactive
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.

4 participants