Add `Middleware#remove` to delete middleware or raise if not found. by p8 · Pull...
source link: https://github.com/rails/rails/pull/42821
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Summary
Middleware#remove
works just like Middleware#delete
but will
raise an error if the middleware isn't found.
This partly reverts 07558ff, where delete
would raise an error.
It might be expected that delete
fails silently for some environments.
Or maybe you want to make sure a middleware isn't present.
See: #42655 (comment)
cc @jhawthorn
Co-authored-by: Alex Ghiculescu [email protected]
@@ -130,7 +130,11 @@ def swap(target, *args, &block)
ruby2_keywords(:swap)
def delete(target)
middlewares.reject! { |m| m.name == target.name } || (raise "No such middleware to delete: #{target.inspect}")
middlewares.reject! { |m| m.name == target.name }
p8 4 days ago •
Author
Member
The original implementation used delete_if
instead of reject!
.delete_if
returns the middlewares
if nothing is found.reject!
returns nil if nothing is found.
Array#delete also returns nil if no matching item is found, so reject!
seems the better choice.
@ghiculescu Yes, would be nice as well.
No one assigned
None yet
No milestone
Successfully merging this pull request may close these issues.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK