I see the file not being there an exceptional case. Making config_for not
raise if the file doesn't exists can lead to more problems like not reading
the config file because of a typo in the file name.

```
if config_for(:rdis)
  # configure the thing
else
  # don't configure the thing
end
```

The block version would be weird too:

```
redis_config = config_for(:redis) do
  # don't configure the thing
end

Redis.config = redis_config
```

The only solution that would work is the helper to check the file existence.


On Wed, Oct 28, 2015 at 5:38 PM Chris Nicola <[email protected]> wrote:

> Currently `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 `config_exists?`
>
> 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.
>
> 1. Provide alternative configuration logic when the file isn't found
> 2. Don't configure the component when the file isn't found and log a
> warning
>
> For example:
>
> ```
> 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.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to