Application#config_for raises an exception whenever a config file isn’t found. However, this doesn’t really seem very exceptional to me and there are going to be a lot of times where I want to configure an application module only if the configuration is available and something else if it isn’t.
I could of course check if the file exists on my own, but then that almost entirely defeats the convenience of this convenience function.
A few possible solutions:
Offer an easy way to check if the file exists like
I don’t like this because it feels too much like a nil checking pattern.
Allow config_for to accept a block or argument
This is similar to the
Hash#fetch pattern, and the value of the block can be returned to the caller. The default exception behavior can remain if no value or block is provided. This would also allow for a few patterns.
Provide alternative configuration logic when the file isn’t found
Don’t configure the component when the file isn’t found and log a warning
if config_for(:the_thing, false) # configure the thing else # don't configure the thing logger.warn "The thing is not configured, no configuration file is found end
I’m definitely open to other suggestions, but the way
config_for works right now I’m very hesitant to use it.