Update AASM compiler to handle custom name and namespace #1387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When trying to replace our home-rolled DSL compiler for AASM, we realized the tapioca one does not handle two features of AASM we're relying on:
aasm(:status) { }
).aasm(namespace: :foo) { }
).This PR adds tests for those and updates the compiler to support them.
Implementation
When you call
SomeClass.aasm
you're actually implicitly callingSomeClass.aasm(:default)
which tells AASM to create a state machine with the name:default
. This means that if you define your state machine likeaasm(:something)
, it's saved under the name:something
so when you callaasm
(again, which is reallyaasm(:default)
) you're going to see an "empty" state machine with no states or events because you're looking at a totally different state machine.Here's the source: https://github.com/aasm/aasm/blob/2e952ff2088082c9f00c95e3c1261afc826f737c/lib/aasm/aasm.rb#L27-L64
This PR updates the compiler to look at all state machines for a given constant when gathering the states and events for which to generate RBI.
If you're using a namespace:
some_state?
andSTATE_SOME_STATE
(source)Tests
I added failing specs, then in the second commit wrote the code to make them pass.