jeremyevans / rodauth

Ruby's Most Advanced Authentication Framework
http://rodauth.jeremyevans.net
MIT License
1.69k stars 95 forks source link

Assign internal request subclass to a constant #187

Closed janko closed 2 years ago

janko commented 2 years ago

For named auth classes, internal request subclass is still anonymous:

class RodauthMain < Rodauth::Auth
end

class RodauthApp < Roda
  plugin :rodauth, auth_class: RodauthMain do
    enable :internal_request
  end
end

RodauthMain.internal_request_eval do
  self.class #=> #<Class:0x0000000143b57680>
end

I thought it would be nice for introspection and error messages if the internal subclass was assigned into a constant for named auth classes. With the changes in this pull request, we now have:

RodauthMain.internal_request_eval do
  self.class #=> RodauthMain::InternalRequest
end

This is especially useful with rodauth-rails, which exposes an instance class method that returns an internal request instance:

rodauth = RodauthMain.instance
rodauth #=> #<RodauthMain::InternalRequest ...>

We make the constant private to ensure it stays internal.

jeremyevans commented 2 years ago

This seems fine. I've merged it locally. I'm going to always set the constant, since there is no problem setting the constant even if the auth class is anonymous.