Conversation
cd285a7 to
c0d880c
Compare
lib/boba/enums_railtie.rb
Outdated
|
|
||
| # Add typed enum methods for each enum | ||
| definitions.each_key do |name| | ||
| enum_values = defined_enums.fetch(name.to_s) |
There was a problem hiding this comment.
We purposefully use the defined_enums method from ActiveRecord, as opposed to using the definitions hash that is passed in
This way we can rely on the normalization that happens when the enums are defined. For instance enum status: [:created, :in_progress] is a valid way to define an enum. And the defined_enums normalizes that so we get a hash like { 'status' => { 'created' => 0, 'in_progress' => 1 } }
Allows us to always expect string keys, and know that we will have the correct values for each variant, even in Rails defined them for the user!
f293ba6 to
9148a43
Compare
Take Updates from `main@upstream`
14d7974 to
1d320c7
Compare
1d320c7 to
5c26004
Compare
|
Hey @coreyja , Thanks a bunch for this contribution. I think there must be a way to set this up to configure which railties get applied, just need to figure out how to do it in an elegant way. I will need to experiment to figure out what that is (not sure if you have an idea here, but I was thinking of something similar to how Datadog instrumentation is configured). I'm pretty swamped with other work at the moment, but will try to find some time to jam on this in the next week or two |
Closes #3
As discussed in that issue we at Wellsheet are in the proccess of migrating from
sorbet-railstotapiocadsl. And one issue for us was our heavy use of ActiveRecord enums and theT::Enumclasses that SorbetRails was generating passed on thoseThis PR adds both a new DSL compiler
ActiveRecordTypedEnumand a new RailtieEnumsRailtie.One thing this PR does NOT yet include, but was mentioned on the issue is a way to make this behavior opt-in. It currently follows the pattern of
RelationsRailtiewhich is included by default.I want to think about the best way to make this opt-in, and thought I'd get this draft up and see if anyone else has ideas as well!