README.md in rails-settings-cached-2.3.4 vs README.md in rails-settings-cached-2.3.5
- old
+ new
@@ -149,48 +149,62 @@
=> { key: "host", type: :string, default: "http://example.com", readonly: true }
Setting.get_field("app_name")
=> { key: "app_name", type: :string, default: "Rails Settings", readonly: false }
```
-## Readonly field
+## Use Setting in Rails initalizing:
-Sometimes you may need to use Setting before Rails is initialized, for example `config/devise.rb`
+In `version 2.3+` we allows you to use Setting before Rails is initialized.
+For example `config/initializers/devise.rb`
+
```rb
Devise.setup do |config|
if Setting.omniauth_google_client_id.present?
config.omniauth :google_oauth2, Setting.omniauth_google_client_id, Setting.omniauth_google_client_secret
end
end
```
-In this case, you must define the `readonly` field:
-
```rb
class Setting < RailsSettings::Base
- # cache_prefix { "v1" }
- field :omniauth_google_client_id, default: ENV["OMNIAUTH_GOOGLE_CLIENT_ID"], readonly: true
- field :omniauth_google_client_secret, default: ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"], readonly: true
+ field :omniauth_google_client_id, default: ENV["OMNIAUTH_GOOGLE_CLIENT_ID"]
+ field :omniauth_google_client_secret, default: ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"]
end
```
-## Use Setting in Rails initalizing:
+## Readonly field
-You can't use Setting in these locations:
+You may also want use Setting in these locations:
```
config/application.rb
config/environments/*.rb
```
-If you wants do that, put the setting into `config/initializers/*.rb`
+If you want do that do that, the setting field must has `readonly: true`.
For example:
```rb
-# config/initializers/devise.rb
-Devise.setup do |config|
- config.omniauth :twitter, Setting.twitter_api_key, Setting.twitter_api_secret
+class Setting < RailsSettings::Base
+ field :mailer_provider, default: (ENV["mailer_provider"] || "smtp"), readonly: true
+ field :mailer_options, type: :hash, readonly: true, default: {
+ address: ENV["mailer_options.address"],
+ port: ENV["mailer_options.port"],
+ domain: ENV["mailer_options.domain"],
+ user_name: ENV["mailer_options.user_name"],
+ password: ENV["mailer_options.password"],
+ authentication: ENV["mailer_options.authentication"] || "login",
+ enable_starttls_auto: ENV["mailer_options.enable_starttls_auto"]
+ }
+end
+```
+
+```rb
+Rails.application.configure do
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.smtp_settings = Setting.mailer_options.deep_symbolize_keys
end
```
### Caching flow: