rails-settings-cached 2.3.4 → 2.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08fedca17d5c8848f9503a0b9a2d45403fd545406ec656d899af182334d6c3ac'
4
- data.tar.gz: 1b928531e53c09d4ac3c582785aad54dee23f81c00721857009c0495ee1a7f30
3
+ metadata.gz: 23b68e0d113892e9f08e29c3e70e39d79f3ce58aed36a981c55fe81593b8f3a9
4
+ data.tar.gz: c144240c649762ee4495fee8e2eef504244ae37746e43c294cef3512ea813a4c
5
5
  SHA512:
6
- metadata.gz: 8f742e343ecfe97413a17aafefead8f5e49a49d407e269962a90e08a3f8ad89441f0ba95f4496a80b8528f68d5edecccf930f00af39627020d75a8e947ac28a5
7
- data.tar.gz: 970ef16a4a2f2c3c552f0d80d8386d5124e3821c0f9ed54d2ad3b0dd57e3c37a7cf94a6342c14d4cb585a6e188c2659ba13034607768eb2dfd29680c5c084a5f
6
+ metadata.gz: f094b5b2485041c04885b1097715bf046e3a5525b88d800242479edaa3190fba4b3f164729840f2b11c519862387893c69ce58085d5867deab74093f75bfee1b
7
+ data.tar.gz: 20d36398a118661a50d45cbfbc16b416f280ef46376c96acbae2a15226ac1f2c70483adcdaacc56530169d6a96ad1e9ac4f79234766c13e2e80a5faaf5e289f6
data/README.md CHANGED
@@ -151,9 +151,11 @@ Setting.get_field("app_name")
151
151
  => { key: "app_name", type: :string, default: "Rails Settings", readonly: false }
152
152
  ```
153
153
 
154
- ## Readonly field
154
+ ## Use Setting in Rails initalizing:
155
155
 
156
- Sometimes you may need to use Setting before Rails is initialized, for example `config/devise.rb`
156
+ In `version 2.3+` we allows you to use Setting before Rails is initialized.
157
+
158
+ For example `config/initializers/devise.rb`
157
159
 
158
160
  ```rb
159
161
  Devise.setup do |config|
@@ -163,33 +165,45 @@ Devise.setup do |config|
163
165
  end
164
166
  ```
165
167
 
166
- In this case, you must define the `readonly` field:
167
-
168
168
  ```rb
169
169
  class Setting < RailsSettings::Base
170
- # cache_prefix { "v1" }
171
- field :omniauth_google_client_id, default: ENV["OMNIAUTH_GOOGLE_CLIENT_ID"], readonly: true
172
- field :omniauth_google_client_secret, default: ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"], readonly: true
170
+ field :omniauth_google_client_id, default: ENV["OMNIAUTH_GOOGLE_CLIENT_ID"]
171
+ field :omniauth_google_client_secret, default: ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"]
173
172
  end
174
173
  ```
175
174
 
176
- ## Use Setting in Rails initalizing:
175
+ ## Readonly field
177
176
 
178
- You can't use Setting in these locations:
177
+ You may also want use Setting in these locations:
179
178
 
180
179
  ```
181
180
  config/application.rb
182
181
  config/environments/*.rb
183
182
  ```
184
183
 
185
- If you wants do that, put the setting into `config/initializers/*.rb`
184
+ If you want do that do that, the setting field must has `readonly: true`.
186
185
 
187
186
  For example:
188
187
 
189
188
  ```rb
190
- # config/initializers/devise.rb
191
- Devise.setup do |config|
192
- config.omniauth :twitter, Setting.twitter_api_key, Setting.twitter_api_secret
189
+ class Setting < RailsSettings::Base
190
+ field :mailer_provider, default: (ENV["mailer_provider"] || "smtp"), readonly: true
191
+ field :mailer_options, type: :hash, readonly: true, default: {
192
+ address: ENV["mailer_options.address"],
193
+ port: ENV["mailer_options.port"],
194
+ domain: ENV["mailer_options.domain"],
195
+ user_name: ENV["mailer_options.user_name"],
196
+ password: ENV["mailer_options.password"],
197
+ authentication: ENV["mailer_options.authentication"] || "login",
198
+ enable_starttls_auto: ENV["mailer_options.enable_starttls_auto"]
199
+ }
200
+ end
201
+ ```
202
+
203
+ ```rb
204
+ Rails.application.configure do
205
+ config.action_mailer.delivery_method = :smtp
206
+ config.action_mailer.smtp_settings = Setting.mailer_options.deep_symbolize_keys
193
207
  end
194
208
  ```
195
209
 
@@ -142,20 +142,19 @@ module RailsSettings
142
142
  end
143
143
 
144
144
  def _value_of(var_name)
145
- unless table_exists?
145
+ unless _table_exists?
146
146
  # Fallback to default value if table was not ready (before migrate)
147
- puts "WARNING: table: \"#{table_name}\" does not exist, `#{name}.#{var_name}` fallback to returns the default value."
147
+ puts "WARNING: table: \"#{table_name}\" does not exist or not database connection, `#{name}.#{var_name}` fallback to returns the default value."
148
148
  return nil
149
149
  end
150
150
 
151
151
  _all_settings[var_name.to_s]
152
- rescue => e
153
- if e.message.include?("connect")
154
- puts "WARNING: `#{name}.#{var_name}` called but no connection, fallback to returns the default value."
155
- return nil
156
- end
152
+ end
157
153
 
158
- raise e
154
+ def _table_exists?
155
+ table_exists?
156
+ rescue => e
157
+ false
159
158
  end
160
159
 
161
160
  def rails_initialized?
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.3.4"
6
+ "2.3.5"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-settings-cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement