Closed hoverjet closed 1 month ago
I believe this introduces a dependency on Rails? Pundit should not have Rails as a dependency.
I hope that by adding the condition require "pundit/railtie" if defined?(Rails)
, it is ensured that the gem can be used in both Rails and non-Rails Ruby environments. This makes the inclusion of the Railtie and generators optional and dependent on the runtime context.
I hope that by adding the condition
require "pundit/railtie" if defined?(Rails)
, it is ensured that the gem can be used in both Rails and non-Rails Ruby environments. This makes the inclusion of the Railtie and generators optional and dependent on the runtime context.
I believe you're correct, that seems like it's the recommended approach when viewing the documentation: https://api.rubyonrails.org/classes/Rails/Railtie.html
I'm for the spirit of more guidance in how to use Pundit, and making it more convenient.
However, I'm significantly more hesitant towards providing and maintaining controller generation templates. That's a lot of code to have an opinion on, when Pundit is mostly only concerned with a relatively small part of the generated code.
My gut feeling is that I'd like a more surgical approach. I'm not sure that's possible.
Regardless I feel I also need to run this PR by another maintainer friend before making a decision.
I also missed that this PR was born out of https://github.com/varvet/pundit/issues/735
It's worth mentioning that I still think that generating policies automatically on scaffold is a good idea. Pundit kind of own policies in that sense, and can have opinions on how to write those.
Thank you for your work. I've decided that maintaining controller templates is not something for Pundit to do.
This PR introduces a Pundit generator for Rails scaffolds and adds
authorize
andpolicy_scope
Pundit's methods to scaffolded controllers. It modifies the scaffold generator to include a hook for Pundit policies and overrides scaffold controller templates through a Railtie to add Pundit's methods. Example scaffold command:Generated
PostsController
: