-
Notifications
You must be signed in to change notification settings - Fork 0
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
Avoid loading/rendering in Rails if SKIP_CONSULT
is set
#40
Conversation
lib/consult/rails/engine.rb
Outdated
@@ -6,6 +6,8 @@ module Rails | |||
# on app boot. | |||
class Railtie < ::Rails::Railtie | |||
config.before_configuration do | |||
next if %w[1 true].include? ENV['SKIP_CONSULT'].to_s.downcase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a Rails-ism to do .present?
(eg), but that seems worse than checking for a truthy value 🤔
There's no functional difference, but I wonder about blocking the auto-load vs short circuiting the method. in other words, doing this:
https://github.com/veracross/consult/blob/master/lib/consult.rb#L103 |
Good idea. Something I was considering is if we'll ever want to get between load and render. I was almost going to do Here's a test question to decide between the current approach and your suggestion... can we imagine any scenario where loading the Railtie integration is useful, but we also don't want to load/render? If yes, then we should keep my approach. If no, then I think yours is better. (I currently can't think of any reason we'd want to load the Railtie if we aren't going to do anything). |
I don't necessarily think this would be better and this seems handy enough in other situations but here's an alternative for your acute problem: You don't necessarily have to load Rails at all to run your rake task. Call the rake tasks with You are checking the rails environment but that can be passed into the rake task as a separate argument or could be read from the environment instead. |
I'd probably still need something from Consult here for things like |
I could be wrong but I think access is JIT, so if templates aren't rendered no Vault/Consul access will be attempted.
Not that I can think of off the top of my head. |
The Lines 42 to 43 in 4a90ccf
Great, I'll redo this PR with your suggestion instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. LGTM
In certain situations, Consult might be loaded by Rails but you don't want it to process templates. For example, from a Rake task that doesn't load the Rails environment. To support those scenarios, you can run the task (etc) with
SKIP_CONSULT=true
and it won't do anything.I don't think we can do an automated test in this repo for this feature, since otherwise we'd need a dummy Rails app. Adding that might be a good idea for the future, though.
Question: Is there a better way to do this?