Closed rainerborene closed 1 year ago
Hello @rainerborene, thanks for the PR. I'm a bit confused by this request though as exposures are lazy already by using expose
.
They are only forced when you expose!
.
@mattpolito Sorry, I didn't make myself clear. This feature improves expose!
by allowing you to eliminate lazy loadiness on specific controller actions. expose!
runs on every controller action by default, and that's the problem. It's worth mentioning that expose!
will not eliminate lazy load of ActiveRecord collections unless you call load
explicity.
@mattpolito Do you think this pull request could be simplified to this instead?
def expose!(name, *args, **options, &block)
before_options = options.extract!(:only, :except)
expose name, *args, **options, &block
before_action name, before_options
end
That would definitely be clearer as far as code goes, however, could you describe a scenario where you would need this? We've used DE for many many years and haven't run into a scenario where this has come up. I'm curious where you're running into this.
@mattpolito Fair enough. Say you have comments
collection that could trigger an exception based on current user permission, and also, you want to run it only for index
action. I think the obvious and most common scenario is when you don't have restful routes. You don't want to expose!
comments on every controller action, right?
Understood. Is there a reason you don't want to use expose
then? Based on your description it would seem like that's what you're looking for.
expose!
would only be for when you need the exposure loaded ahead of time. Honestly I've never once needed to use it.
One of the drawbacks of
expose!
is that it run on every controller action. The idea behind this pull request is to allow developers to eliminate lazy loadiness on specific actions without the weirdness ofbefore_action :thing, except: :sort
. So, instead you can usebefore_action :load_thing, except: :sort
. More clarity and better naming conventions. It will also really eliminate lazy load for ActiveRecord collections by callingload
before.