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

Allow subclasses to override ShowExceptions::TEMPLATE #1223

Merged
merged 2 commits into from
Apr 14, 2018

Conversation

jkowens
Copy link
Contributor

@jkowens jkowens commented Jan 5, 2018

This issue came up in the Sinatra project. Sinatra extends Rack::ShowExceptions to implement a custom template, but the only way to do that right now with this code:

https://github.com/sinatra/sinatra/blob/master/lib/sinatra/show_exceptions.rb#L364

Rack::ShowExceptions.send :remove_const, "TEMPLATE"
Rack::ShowExceptions.const_set "TEMPLATE", Sinatra::ShowExceptions::TEMPLATE

This was added after #922, but this causes problems when Sinatra is mounted along with other Rack apps.

See: sinatra/sinatra/issues/1376

@namusyaka
Copy link

Hello, rack maintainers.

As Rack's opinion, is it assumed that the framework that conforms to Rack inherits this exception class and uses it as a use case? If so, you should provide a standard way, not just this way.
Unfortunately, due to #922, we simply lost the technique to inherit and extend this class for defining custom template.
I am pleased to receive your opinion.

end

def template
self.class::TEMPLATE
Copy link
Contributor Author

@jkowens jkowens Jan 15, 2018

Choose a reason for hiding this comment

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

Referencing TEMPLATE in this way allows subclasses to define the TEMPLATE constant. Subclasses also have the choice of overriding the #template method instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. It is better to use just TEMPLATE here and only allow subclasses to override #template instead of a constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok good call. I've updated the PR, thanks!

end

def template
self.class::TEMPLATE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. It is better to use just TEMPLATE here and only allow subclasses to override #template instead of a constant.

@rafaelfranca
Copy link
Collaborator

hello @namusyaka. After this PR do you still think it is not possible to inherit and extend this class to define custom templates?

@namusyaka
Copy link

Nope, current change looks fine to me. Thank you! @rafaelfranca @jkowens

@tenderlove tenderlove merged commit 17fb74d into rack:master Apr 14, 2018
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.

4 participants