-
Notifications
You must be signed in to change notification settings - Fork 110
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
activemodel: ActiveModel::Errors#add accepts String and Proc for type #717
activemodel: ActiveModel::Errors#add accepts String and Proc for type #717
Conversation
@sanfrecce-osaka Thanks for your contribution! Please follow the instructions below for each change. Available commandsYou can use the following commands by commenting on this PR.
|
d783e3c
to
0b39c22
Compare
… type The behavior of passing String or Proc for type should be allowed. FYI: It is documented in 6.1, but It is already available in 6.0. cf. rails/rails@fcd1e41#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R368-R374 cf. rails/rails@d9011e3#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R370 Also, the name of the second argument was changed from `message` to `type` in 6.1.
0b39c22
to
fe5bb2d
Compare
gems/activemodel/6.0/activemodel.rbs
Outdated
# # => {:base=>["either name or email must be present"]} | ||
# person.errors.details | ||
# # => {:base=>[{error: :name_or_email_blank}]} | ||
def add: (untyped attribute, ?::Symbol | ::String | ^(untyped base, ::Hash[untyped, untyped]) -> (::Symbol | ::String) type, ?::Hash[untyped, untyped] options) -> void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes you think return type should be void
instead of ActiveModel::Error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback.
ActiveModel::Error was added on 6.1.
On 6.1 or later, ActiveModel::Errors#add returns ActiveModel::Error.
On the other hand, ActiveModel::Errors#add
returns messages array on rails 6.0, because last evaluated is Array#<<
.
cf. https://github.com/rails/rails/blob/v6.0.0/activemodel/lib/active_model/errors.rb#L311-L322
Currently in gem_rbs_collection, activemodel type definitions are defined 6.0 and 7.0, but not 6.1.
cf. #615
So I fixed them on 174b6ce
…o 6.0 and 7.0 ActiveModel::Error was added on 6.1. cf. rails/rails@ef68d3e On 6.1 or later, ActiveModel::Errors#add returns ActiveModel::Error. On the other hand, `ActiveModel::Errors#add` returns messages array on rails 6.0, because last evaluated is `Array#<<`. cf. https://github.com/rails/rails/blob/v6.0.0/activemodel/lib/active_model/errors.rb#L311-L322 Currently in gem_rbs_collection, activemodel type definitions are defined 6.0 and 7.0, but not 6.1. cf. ruby#615 So I divide type definition of ActiveModel::Errors#add to 6.0 and 7.0.
4981ed6
to
174b6ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APPROVE
Thanks for your review, @ksss! @sanfrecce-osaka, @ksss This PR is ready to be merged. |
…ors-add # Conflicts: # gems/activemodel/6.0/activemodel-6.0.rbs
/merge |
This PR is not approved yet by the reviewers. Please get approval from the reviewers. See the Actions tab for detail. |
Sorry, I resolved conflict. Please re-review 🙏 🙏 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APPROVE
Thanks for your review, @ksss! @sanfrecce-osaka, @ksss This PR is ready to be merged. |
/merge |
The behavior of passing String or Proc for type should be allowed.
FYI: It is documented in 6.1, but It is already available in 6.0.
cf. rails/rails@fcd1e41#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R368-R374
cf. rails/rails@d9011e3#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R370
Also, the name of the second argument was changed from
message
totype
in 6.1.