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 +4 -4
- data/README.md +27 -13
- data/lib/rails-settings/base.rb +7 -8
- data/lib/rails-settings/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23b68e0d113892e9f08e29c3e70e39d79f3ce58aed36a981c55fe81593b8f3a9
|
4
|
+
data.tar.gz: c144240c649762ee4495fee8e2eef504244ae37746e43c294cef3512ea813a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
##
|
154
|
+
## Use Setting in Rails initalizing:
|
155
155
|
|
156
|
-
|
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
|
-
|
171
|
-
field :
|
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
|
-
##
|
175
|
+
## Readonly field
|
177
176
|
|
178
|
-
You
|
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
|
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
|
-
|
191
|
-
|
192
|
-
|
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
|
|
data/lib/rails-settings/base.rb
CHANGED
@@ -142,20 +142,19 @@ module RailsSettings
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def _value_of(var_name)
|
145
|
-
unless
|
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
|
-
|
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
|
-
|
154
|
+
def _table_exists?
|
155
|
+
table_exists?
|
156
|
+
rescue => e
|
157
|
+
false
|
159
158
|
end
|
160
159
|
|
161
160
|
def rails_initialized?
|
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
|
+
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
|