-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One idea: allow before_filter to customize engine args. Test needed #36
base: master
Are you sure you want to change the base?
Conversation
@magibney says:
There are ways you could do this without if-else. I think you can actually put whatever you want as a configuration, so you could:
I think that would work, or something along those lines, but haven't tested it. BentoSearch is meant to give you the tools you need to easily and elegantly build the architecture that works for you, not neccesarily provide every architecture you might need out of the box. But I'm still not certain how common this use case is and how pretty we need to make it.
So, we could have it insist on calling safe_search_args even if you have a custom filter. I'm not sure if that's better or worse -- if you're customizing, maybe you want to do your own thing there, and not be forced into the safe_search_args architecture? If you do want to use it currently, you do have to make sure to call That said, some final points:
|
If you don't want to share details of your use case publically, you can email me instead. But I'd really love to understand why and what you're actually needing to do here, and I really don't right now! |
This all looks great to me. I wasn't intending to press on #35, and I'm fine with it being closed; I was just thinking out loud about some of its potential benefits. Thanks for pointing out the possibility of packaging the params_logic in the conf. I wasn't aware that that was a possibility, and something along the lines of what you suggest seems to answer my main (though minor, at that) concern. re: For completeness' sake, I will email you about use case details, but I'm pretty certain (especially with the approach you suggest in this comment) that #36 will work more than adequately for my use case. Thanks for all the consideration you've put into this! |
Had to change Example code as it worked for me: BentoSearch.register_engine('summon') do |conf|
...
conf.check_auth = lambda do |param_hash, request|
auth_header = request.headers['authorization']
if verify_auth?(auth_header)
param_hash[:auth] = true
else
param_hash[:auth] = false
end
param_hash
end
end
BentoSearch::SearchController.before_action do |controller|
check_auth = controller.engine.configuration.check_auth
if check_auth != nil
engine_params = controller.safe_search_args(controller.engine, controller.params)
engine_params = check_auth.call(engine_params, controller.request)
controller.engine_params = engine_params
end
end |
b82b81b
to
266875c
Compare
Thanks, fixed that bug. Just gotta figure out how to write a test for this. |
No description provided.