Reputation: 3513
I used to see a lot of gems where you would configure them in your application.rb
file or one of the environment files because they hooked into Railtie's configuration helpers. But now it seems every gem I use handles configuration by having an initializer file with a custom configuration implementation (for example Devise's Devise.setup do |config|
).
I suspect one reason for this is that the gems I'm using just happen to have a lot of configuration options, so it makes sense to use an initializer. But are there any other reasons not to use Railtie's config
?
Let's say I'm building a gem and I only want to expose a few options for user configuration. What are the pros and cons of using an initializer file with custom setup logic versus using Railties?
Upvotes: 1
Views: 252
Reputation: 101811
Using an initializer file avoids tying the configuration of the gem to the specific details of how the framework loads configuration.
Take Devise here for example - if the railtie hook changed it would suddenly revert to the default behavior. This means that the maintainers would need to change both the generator and template and end users would need to change their configuration when upgrading rails.
It is also very straight forward to uninstall gems which use an initializer file.
Upvotes: 0