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 prefix functionality to scopes to facilitate multiple state machines on one model. #14

Merged
merged 12 commits into from
Jun 26, 2024

Conversation

nicholalexander
Copy link
Contributor

@nicholalexander nicholalexander commented Feb 25, 2024

When using multiple state machines on a single model, one might want more control over their scopes. In order to allow that, this PR adds handling a hash with some prefix options that works similar to how delegate in rails works. You can pass in scopes: { prefix: true } to get your scope prefixed with your attribute or scopes: { prefix: 'some_custom_prefix' } to get your scope prefixed with a custom prefix.

This PR also adds associated tests and updates the Readme.

README.md Outdated
# ...
end

steady_state :temperature, scopes: true, scopes_prefix: 'temperature' do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
steady_state :temperature, scopes: true, scopes_prefix: 'temperature' do
steady_state :temperature, scopes: { prefix: true } do

I might propose this style (similar to Rails' delegate prefix option), where prefix: true would default to the name of the state field, and prefix: 'something_else' would allow you to override it with something else.

Copy link
Member

Choose a reason for hiding this comment

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

(Otherwise, I love the idea -- Going to wait to review the underlying implementation until the API is settled -- LMK when it's ready for review!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! And also, I really like the idea to make it like rails delegate.. When Ray and I were talking about this, he also thought about prefix: true but we didn't make the connection to do it all three ways. I will update the PR and write a description shortly!

@nicholalexander nicholalexander changed the title WIP: Nca/prefix scopes idea Add prefix functionality to scopes to facilitate multiple state machines on one model. Feb 27, 2024
@nicholalexander nicholalexander marked this pull request as ready for review February 27, 2024 18:04
@nicholalexander nicholalexander marked this pull request as draft March 14, 2024 13:58
@nicholalexander nicholalexander changed the title Add prefix functionality to scopes to facilitate multiple state machines on one model. WIP: Add prefix functionality to scopes to facilitate multiple state machines on one model. Mar 14, 2024
@nicholalexander nicholalexander changed the title WIP: Add prefix functionality to scopes to facilitate multiple state machines on one model. Add prefix functionality to scopes to facilitate multiple state machines on one model. Mar 16, 2024
@nicholalexander nicholalexander marked this pull request as ready for review March 16, 2024 16:16
@nicholalexander nicholalexander requested a review from smudge March 21, 2024 12:53
smudge
smudge previously approved these changes Jun 6, 2024
Copy link
Member

@smudge smudge left a comment

Choose a reason for hiding this comment

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

domain LGTM

Copy link
Member

@smudge smudge left a comment

Choose a reason for hiding this comment

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

platform TAFN -- just the one note! Mostly a thought about how to get an ArgumentError idiomatically, but overall, this looks great.

Before you merge, you may also want to bump the version number so that I can cut you a release right away. (Not that you need this urgently or anything... apologies for the slow review. 😅)

@nicholalexander
Copy link
Contributor Author

platform TAFN -- just the one note! Mostly a thought about how to get an ArgumentError idiomatically, but overall, this looks great.

Before you merge, you may also want to bump the version number so that I can cut you a release right away. (Not that you need this urgently or anything... apologies for the slow review. 😅)

Will also bump version number! No apologies necessary!

Copy link
Member

@smudge smudge left a comment

Choose a reason for hiding this comment

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

domain LGTM && platform LGTM!

Looks like a dependabot merge may have messed up the build matrix gemfiles. You can run bundle exec appraisal install to regenerate those, or we can do that in a separate PR.

@smudge
Copy link
Member

smudge commented Jun 14, 2024

@nicholalexander fixed the build issue over here:
#17

@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SteadyState
VERSION = '1.1.0'
VERSION = '1.2.0'
Copy link
Member

Choose a reason for hiding this comment

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

I think you'll need to re-run bundle install and bundle exec appraisal install (and bundle exec rubocop -A if appraisal introduces linter errors, lol), and then commit those changes. That should be the last piece of this that will unblock your build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I started on this yesterday and got sidetracked - should be incoming!

Copy link
Member

@smudge smudge left a comment

Choose a reason for hiding this comment

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

domain LGTM && platform LGTM!

@smudge smudge merged commit 5340b91 into Betterment:main Jun 26, 2024
7 checks passed
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.

2 participants