-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(activemodel): Divide type definition of ActiveModel::Errors#add t…
…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 6.0 and 7.0, not 6.1. cf. #615 So I divide type definition of ActiveModel::Errors#add to 6.0 and 7.0.
- Loading branch information
1 parent
fe5bb2d
commit 4981ed6
Showing
5 changed files
with
116 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module ActiveModel | ||
class Errors | ||
# Adds +message+ to the error messages and used validator type to +details+ on +attribute+. | ||
# More than one error can be added to the same +attribute+. | ||
# If no +message+ is supplied, <tt>:invalid</tt> is assumed. | ||
# | ||
# person.errors.add(:name) | ||
# # => ["is invalid"] | ||
# person.errors.add(:name, :not_implemented, message: "must be implemented") | ||
# # => ["is invalid", "must be implemented"] | ||
# | ||
# person.errors.messages | ||
# # => {:name=>["is invalid", "must be implemented"]} | ||
# | ||
# person.errors.details | ||
# # => {:name=>[{error: :not_implemented}, {error: :invalid}]} | ||
# | ||
# If +message+ is a symbol, it will be translated using the appropriate | ||
# scope (see +generate_message+). | ||
# | ||
# If +message+ is a proc, it will be called, allowing for things like | ||
# <tt>Time.now</tt> to be used within an error. | ||
# | ||
# If the <tt>:strict</tt> option is set to +true+, it will raise | ||
# ActiveModel::StrictValidationFailed instead of adding the error. | ||
# <tt>:strict</tt> option can also be set to any other exception. | ||
# | ||
# person.errors.add(:name, :invalid, strict: true) | ||
# # => ActiveModel::StrictValidationFailed: Name is invalid | ||
# person.errors.add(:name, :invalid, strict: NameIsInvalid) | ||
# # => NameIsInvalid: Name is invalid | ||
# | ||
# person.errors.messages # => {} | ||
# | ||
# +attribute+ should be set to <tt>:base</tt> if the error is not | ||
# directly associated with a single attribute. | ||
# | ||
# person.errors.add(:base, :name_or_email_blank, | ||
# message: "either name or email must be present") | ||
# person.errors.messages | ||
# # => {: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) -> Array[String] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
class Person | ||
include ActiveModel::Model | ||
include ActiveModel::Validations | ||
extend ActiveModel::Validations::ClassMethods | ||
|
||
attr_accessor name: String? | ||
attr_accessor email: String? | ||
|
||
def should_be_satisfied_special_email_rule: () -> void | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters