Crystal 0.27.0 support#225
Conversation
| raise Crecto::InvalidType.new("Format validator can only validate strings") unless @instance_hash.fetch(format[:field]).is_a?(String) | ||
| val = @instance_hash.fetch(format[:field]).as(String) | ||
| raise Crecto::InvalidType.new("Format validator can only validate strings") unless @instance_hash.fetch(format[:field], nil).is_a?(String) | ||
| val = @instance_hash.fetch(format[:field], nil).as(String) |
There was a problem hiding this comment.
I think all the instances of fetch here can be replaced with the regular, non-nilable [], since we're already guarding that the hash has the key on the previous line.
Alternatively, the whole section could be re-written as
if field_value = @instance_hash[format[:field]]?
raise Crecto::InvalidType.new("Format validator can only validate strings") unless field_value.is_a?(String)
add_error(format[:field].to_s, "is invalid") if format[:pattern].match(field_value).nil?
endCrystal's automatic type reduction should ensure that the typing is correct at each point without the need for an .as(String) cast.
There was a problem hiding this comment.
I think all the instances of fetch here can be replaced with the regular, non-nilable []
Yes, but I think fetch still looks better IMO.
the whole section could be re-written as
I will leave that exercise to someone else.
|
Should probably also bump the I'd vote to keep it and/or add a |
|
closes #224 |
Breaking changes for Crystal 0.27.0