Extracted attributes assingment from ActiveRecord to ActiveModel#10776
Conversation
There was a problem hiding this comment.
I don't think this is still necessary.
There was a problem hiding this comment.
Existing rails apps could still use this constant to catch this exception and process it manually.
There was a problem hiding this comment.
Raising it has to trigger a deprecation then.
There was a problem hiding this comment.
Do you know how to do that?
|
Is there a reason why you didn't extract the tests too ? |
|
@dmathieu once I saw someone from core team saying that overlapping between AR and AM tests is good idea. No concrete reason. |
There was a problem hiding this comment.
Could you please indent the private methods as the contribution guideline states ? Also, I think that this will at least need a changelog entry. Not sure if you should add one in AR changelog as well.
There was a problem hiding this comment.
Nice pull request though, thank you!
|
What is the motivation for this extraction? |
|
Using outside of activerecord just like validation and others: Attributes assignment concept is something I personally use a lot for many types of objects. |
|
👍 for the idea from my side. @sgrif WDYT? |
|
👍 for the idea from me, as well. Would like to review the code again once it's been rebased onto master and had tests added/moved/etc |
609006e to
4c14289
Compare
|
Updated the PR:
|
|
I would use this on Mongoid if this is merge on ActiveModel.! |
There was a problem hiding this comment.
Should not this method be private?
4c14289 to
f39d770
Compare
|
@rafaelfranca removed all whitespace |
There was a problem hiding this comment.
AttributesAssignment => AttributeAssignment
…utesAssignment` Allows to use it for any object as an includable module.
f39d770 to
2606fb3
Compare
Minor style changes across the board. Changed an alias to an explicit method declaration, since the alias will not be documented otherwise.
Extracted attributes assingment from ActiveRecord to ActiveModel
|
❤️ |
|
I wonder if, once all non-db-specific logic (including recent one such as the user-facing casting half) is extracted to AM, it would make sense to have a more full-featured out-of-the-box implementation of active model for those that want it to behave not just as a form object but as much as a full AR as possible, except not persisted. That means all the same validations/errors, attribute assignment, casting, etc. Perhaps call it |
There was a problem hiding this comment.
Given that end users may be rescuing from this error in their apps, it seems like a rather long and implementation-specific namespace. Perhaps keep it under ActiveModel::UnknownAttributeError?
There was a problem hiding this comment.
Yep, I agree there ; this is too implementation-specific! 👍
There was a problem hiding this comment.
Agreed, let's leave this undeprecated, and just alias it. It's an unnecessary change for users, and forces them to care too much about implementation.
There was a problem hiding this comment.
Leaving this undeprecated can cause confusion because while constant alias will work the caught exception instances will still have new name. It looks like people are just yelling about too long name space and want it to be sorter like in @egilburg's comment
active_model/forbidden_attributes_protection is not used since rails#10776
Remove redundant require: follow #10776
Now you are able to do:
This is just a proof of concept PR.
There is still some todos:
I am gonna add them if this will be approved to merge in.