I updated pundit from 0.3 to 2.0 after ran into the following issue.
In my controllers, the Error constant gets evaluated as Pundit::Error after I include Pundit. This is causing an issue with my own custom errors which are namespaced under my own Error module.
It looks like this particular issue that I'm running into was introduced by this commit https://github.com/varvet/pundit/commit/a21ad899a70374797df1fd905f3966d8f77a6442
Here's an example of what I'm seeing within the context of irb
irb(main):001:0> require 'pundit'
=> true
irb(main):002:0> include Pundit
=> Object
irb(main):003:0> Error
=> Pundit::Error
I can get around this by doing ::Error::MyCustomError, but I'm reporting this because 1) I don't want to 2) this doesn't seem like the intended behavior.
Moreover, all the error classes defined my pundit have this behavior after including Pundit
irb(main):004:0> NotDefinedError
=> Pundit::NotDefinedError
This behavior seems like it could lead to a lot of unwanted conflicts. The documentation always references errors by their full name, for example, Pundit::NotAuthorizedError, not NotAuthorizedError and this does not seem to be documented behavior. I would be able to search for a solution that does not make constants like NotDefinedError, NotAuthorizedError, and Error available to classes that include Pundit without namespacing them with Pundit:: if this is desired.
Isn鈥檛 this just how Ruby does its constant lookups (which is weird sometimes)?
Well, I guess it could be solved by moving the errors out of the module we include. We still want them namespaced though but some restructuring could help here.
What do you think about: https://github.com/varvet/pundit/pull/590 ?
TODO:
Pundit::Error (#590)I don鈥檛 think we should use compact style for all errors. Instead, we should restructure the code to make this problem go away in a major update.
@Linuus OK cool - I'll update the todo. I don't quite understand what restructuring needs to be done, but we can cross that bridge when we come to it.
Most helpful comment
Isn鈥檛 this just how Ruby does its constant lookups (which is weird sometimes)?
Well, I guess it could be solved by moving the errors out of the module we include. We still want them namespaced though but some restructuring could help here.