Add Administrate::Punditize methods as module methods #2403
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of adding them via
included do
.Note: It's easiest to view this diff if you hide whitespace changes:
If these methods are added via
included do
it makes it hard to override the method in an app's controller.Example:
That example will skip pundit completely, because the
def scoped_resource
fromAdministrate::Punditize
was added viaincluded do
, which means it will behave as if we had defined the method inline twice inAdmin ::ApplicationController
, which will result in the first definition fromAdministrate::Punditize
being ignored. And thesuper
in the code snippet above will refer to the non-punditized definition provided in the base classAdministrate::ApplicationController
:administrate/app/controllers/administrate/application_controller.rb
Lines 192 to 194 in cda8da9
This seems unexpected to me, and makes it hard to add functionality that layers on top of what
Administrate::Punditize
does.However, if we define
def scoped_resource
as a module method inAdministrate::Punditize
thensuper
inAdmin::ApplicationController
will refer to the method defined inAdministrate::Punditize
.Are there gotchas that I'm missing? Is there a reason that some of the methods
in
Administrate::Punditize
were defined viaincluded do
and others wereadded as module methods?