Skip to content
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

Support inserting middleware before/after anonymous classes in the middleware stack #1479

Merged
merged 1 commit into from
Aug 29, 2016
Merged

Support inserting middleware before/after anonymous classes in the middleware stack #1479

merged 1 commit into from
Aug 29, 2016

Conversation

rosa
Copy link
Contributor

@rosa rosa commented Aug 29, 2016

I realised that this commit broke usages of insert_before/insert_after with Grape::Middleware::Error. For example, this is how I use it:

insert_before Grape::Middleware::Error, Grape::Middleware::Logger

Since that commit, Grape::Middleware::Error is inserted in the middleware stack as Class.new(Grape::Middleware::Error). Then, when we try to insert another middleware before or after it, we get:

RuntimeError:
       No such middleware to insert before: Grape::Middleware::Error

The reason is that we don't recognize the anoymous class that represents Grape::Middleware::Error in the stack. This pull-request allows considering the superclass for anonymous classes when comparing middleware within the stack. Feel free to suggest a different way to approach this problem, this was just my personal attempt to fix it in a simple way.

Since `Grape::Middleware::Error` is inserted in the middleware stack as
`Class.new(Grape::Middleware::Error)`, we cannot rely on comparing
classes directly when trying to insert around this middleware. We need
to take into account the superclass, for anonymous classes only.
0.17.0 (7/29/2016)
==================

#### Features

* [#1393](https://github.com/ruby-grape/grape/pull/1393): Middleware can be inserted before or after default Grape middleware - [@ridiculous](https://github.com/ridiculous).
* [#1390](https://github.com/ruby-grape/grape/pull/1390): Allow inserting middleware at arbitrary points in the middleware stack - [@Rosa](https://github.com/Rosa).
* [#1390](https://github.com/ruby-grape/grape/pull/1390): Allow inserting middleware at arbitrary points in the middleware stack - [@rosa](https://github.com/rosa).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the chance to change that to lowercase, I realised I had used uppercase when that PR had already been merged 😅

@dblock
Copy link
Member

dblock commented Aug 29, 2016

This is perfect, thanks.

@dblock dblock merged commit 8709973 into ruby-grape:master Aug 29, 2016
@rosa
Copy link
Contributor Author

rosa commented Aug 29, 2016

Thanks for the super quick review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants