-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Port BeforeTypeCast
to Active Model
#44534
Port BeforeTypeCast
to Active Model
#44534
Conversation
The build failure is due to As a solution, we could check if Perhaps it would be better to move (Note that we already include |
Another thought: since |
b186945
to
eff34f6
Compare
eff34f6
to
5a0ab89
Compare
This commit ports `ActiveRecord::AttributeMethods::BeforeTypeCast` to `ActiveModel::BeforeTypeCast` and includes it in `ActiveModel::Attributes`. Thus, classes that include `ActiveModel::Attributes` will now automatically define methods such as `*_before_type_cast`, just as Active Record models do. The `ActiveRecord::AttributeMethods::BeforeTypeCast` module is kept for backward compatibility, but it now merely includes `ActiveModel::BeforeTypeCast`. Co-authored-by: Petrik <petrik@deheus.net>
5a0ab89
to
cfb72c9
Compare
I'm reverting this PR. I see no justification to move this to Active Model anywhere in the PR description. Sure, it is nice to have, but why would you want those methods in a Active Model class. And it is automatically adding to Attributes, it is no opt-in like the other things in Active Model. |
One example of using rails/actionview/lib/action_view/helpers/tags/base.rb Lines 46 to 52 in ee42128
Another example of how |
I get the theoretical problem, but I want to see examples where applications and libraries are needing those features. Active Model doesn't not have the goal of matching all the Active Record API and features. It provides what is useful, not everything. For example, did you find any form that uses Active Model object that actually need to use the |
I originally submitted this PR because it was an issue I encountered in a gem that I wrote. It's been a long time since I wrote the code, but I think the issue was related to attribute types where the |
Got it. Can we make it work without bringing that entire API? For example, can we just move |
Form helpers also need rails/actionview/lib/action_view/helpers/tags/base.rb Lines 51 to 61 in ee42128
As for rails/activerecord/lib/active_record/message_pack.rb Lines 73 to 79 in 2eace42
Since Active Model is the framework that actually implements the |
I think my question is more, do they need to? If they do need to, them we should be moving all those methods to the |
This commit ports
ActiveRecord::AttributeMethods::BeforeTypeCast
toActiveModel::BeforeTypeCast
and includes it inActiveModel::Attributes
. Thus, classes that includeActiveModel::Attributes
will now automatically define methods such as*_before_type_cast
, just as Active Record models do.The
ActiveRecord::AttributeMethods::BeforeTypeCast
module is kept for backward compatibility, but it now merely includesActiveModel::BeforeTypeCast
.