config_default 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +20 -19
- data/README.md +13 -13
- data/lib/config_default/rails_patch.rb +6 -2
- data/lib/config_default/struct.rb +1 -1
- data/lib/config_default/version.rb +1 -1
- data/lib/config_default.rb +11 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 64815caf5e319e0a0450d51ffcec8e2e90358cad44ea56b96810f05ff7376a4f
|
|
4
|
+
data.tar.gz: 37412fc1357aa64d689bc94310b2208a1b2f120f91a303fb9b2700398fb65110
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e867d8bed4ce7d7fcbd9b0ff5101cb9049954cb69b3212cdba2f891db5c36ab3799fe25997e7a81a0d94b9bcdfe0e6bb5988086537eb37e7ba68fcad05cbb157
|
|
7
|
+
data.tar.gz: 6d1b4e3b838952deb21db1cbddea070703d2737e922db0b2c27c86c795f74c67e075c02cfbc532b8520c1d6279720bc598618d87443c45d02ca7d4fc6e6a8be3
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
config_default (0.5.
|
|
4
|
+
config_default (0.5.4)
|
|
5
5
|
activesupport (>= 6)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
action_text-trix (2.1.
|
|
10
|
+
action_text-trix (2.1.17)
|
|
11
11
|
railties
|
|
12
12
|
actioncable (8.1.2)
|
|
13
13
|
actionpack (= 8.1.2)
|
|
@@ -92,7 +92,7 @@ GEM
|
|
|
92
92
|
date (3.5.1)
|
|
93
93
|
diff-lcs (1.6.2)
|
|
94
94
|
drb (2.2.3)
|
|
95
|
-
erb (6.0.
|
|
95
|
+
erb (6.0.2)
|
|
96
96
|
erubi (1.13.1)
|
|
97
97
|
globalid (1.3.0)
|
|
98
98
|
activesupport (>= 6.1)
|
|
@@ -104,11 +104,11 @@ GEM
|
|
|
104
104
|
prism (>= 1.3.0)
|
|
105
105
|
rdoc (>= 4.0.0)
|
|
106
106
|
reline (>= 0.4.2)
|
|
107
|
-
json (2.
|
|
107
|
+
json (2.19.2)
|
|
108
108
|
language_server-protocol (3.17.0.5)
|
|
109
109
|
lint_roller (1.1.0)
|
|
110
110
|
logger (1.7.0)
|
|
111
|
-
loofah (2.25.
|
|
111
|
+
loofah (2.25.1)
|
|
112
112
|
crass (~> 1.0.2)
|
|
113
113
|
nokogiri (>= 1.12.0)
|
|
114
114
|
mail (2.9.0)
|
|
@@ -120,7 +120,8 @@ GEM
|
|
|
120
120
|
marcel (1.1.0)
|
|
121
121
|
method_source (1.1.0)
|
|
122
122
|
mini_mime (1.1.5)
|
|
123
|
-
minitest (6.0.
|
|
123
|
+
minitest (6.0.2)
|
|
124
|
+
drb (~> 2.0)
|
|
124
125
|
prism (~> 1.5)
|
|
125
126
|
net-imap (0.6.3)
|
|
126
127
|
date
|
|
@@ -132,11 +133,11 @@ GEM
|
|
|
132
133
|
net-smtp (0.5.1)
|
|
133
134
|
net-protocol
|
|
134
135
|
nio4r (2.7.5)
|
|
135
|
-
nokogiri (1.19.
|
|
136
|
+
nokogiri (1.19.2-arm64-darwin)
|
|
136
137
|
racc (~> 1.4)
|
|
137
|
-
nokogiri (1.19.
|
|
138
|
+
nokogiri (1.19.2-x86_64-darwin)
|
|
138
139
|
racc (~> 1.4)
|
|
139
|
-
nokogiri (1.19.
|
|
140
|
+
nokogiri (1.19.2-x86_64-linux-gnu)
|
|
140
141
|
racc (~> 1.4)
|
|
141
142
|
parallel (1.27.0)
|
|
142
143
|
parser (3.3.10.2)
|
|
@@ -180,8 +181,8 @@ GEM
|
|
|
180
181
|
activesupport (>= 5.0.0)
|
|
181
182
|
minitest
|
|
182
183
|
nokogiri (>= 1.6)
|
|
183
|
-
rails-html-sanitizer (1.
|
|
184
|
-
loofah (~> 2.
|
|
184
|
+
rails-html-sanitizer (1.7.0)
|
|
185
|
+
loofah (~> 2.25)
|
|
185
186
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
186
187
|
railties (8.1.2)
|
|
187
188
|
actionpack (= 8.1.2)
|
|
@@ -210,11 +211,11 @@ GEM
|
|
|
210
211
|
rspec-expectations (3.13.5)
|
|
211
212
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
212
213
|
rspec-support (~> 3.13.0)
|
|
213
|
-
rspec-mocks (3.13.
|
|
214
|
+
rspec-mocks (3.13.8)
|
|
214
215
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
215
216
|
rspec-support (~> 3.13.0)
|
|
216
217
|
rspec-support (3.13.7)
|
|
217
|
-
rubocop (1.
|
|
218
|
+
rubocop (1.84.2)
|
|
218
219
|
json (~> 2.3)
|
|
219
220
|
language_server-protocol (~> 3.17.0.2)
|
|
220
221
|
lint_roller (~> 1.1.0)
|
|
@@ -222,14 +223,14 @@ GEM
|
|
|
222
223
|
parser (>= 3.3.0.2)
|
|
223
224
|
rainbow (>= 2.2.2, < 4.0)
|
|
224
225
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
225
|
-
rubocop-ast (>= 1.
|
|
226
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
226
227
|
ruby-progressbar (~> 1.7)
|
|
227
228
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
228
|
-
rubocop-ast (1.49.
|
|
229
|
+
rubocop-ast (1.49.1)
|
|
229
230
|
parser (>= 3.3.7.2)
|
|
230
231
|
prism (~> 1.7)
|
|
231
|
-
rubocop-config-umbrellio (1.
|
|
232
|
-
rubocop (~> 1.
|
|
232
|
+
rubocop-config-umbrellio (1.84.118)
|
|
233
|
+
rubocop (~> 1.84.0)
|
|
233
234
|
rubocop-factory_bot (~> 2.28.0)
|
|
234
235
|
rubocop-performance (~> 1.26.0)
|
|
235
236
|
rubocop-rails (~> 2.34.0)
|
|
@@ -262,7 +263,7 @@ GEM
|
|
|
262
263
|
securerandom (0.4.1)
|
|
263
264
|
stringio (3.2.0)
|
|
264
265
|
thor (1.5.0)
|
|
265
|
-
timeout (0.6.
|
|
266
|
+
timeout (0.6.1)
|
|
266
267
|
tsort (0.2.0)
|
|
267
268
|
tzinfo (2.0.6)
|
|
268
269
|
concurrent-ruby (~> 1.0)
|
|
@@ -275,7 +276,7 @@ GEM
|
|
|
275
276
|
base64
|
|
276
277
|
websocket-extensions (>= 0.1.0)
|
|
277
278
|
websocket-extensions (0.1.5)
|
|
278
|
-
zeitwerk (2.7.
|
|
279
|
+
zeitwerk (2.7.5)
|
|
279
280
|
|
|
280
281
|
PLATFORMS
|
|
281
282
|
arm64-darwin
|
data/README.md
CHANGED
|
@@ -92,7 +92,7 @@ Just create `config/app.default.yml` (test/staging) and `config/app.yml` (stagin
|
|
|
92
92
|
And then in your application load it:
|
|
93
93
|
|
|
94
94
|
```ruby
|
|
95
|
-
config = ConfigDefault.
|
|
95
|
+
config = ConfigDefault.hash(:app)
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
It will load result hash with merging `app.yml` and `app.default.yml` files.
|
|
@@ -101,34 +101,34 @@ So it's mean that what key (string or symbol) you will define in the YAML file =
|
|
|
101
101
|
|
|
102
102
|
You can change this behaviour with `#load` options:
|
|
103
103
|
```ruby
|
|
104
|
-
config = ConfigDefault.
|
|
105
|
-
config = ConfigDefault.
|
|
104
|
+
config = ConfigDefault.hash(:app, symbolize_keys: true) # Hash with symbolized first keys
|
|
105
|
+
config = ConfigDefault.hash(:app, deep_symbolize_keys: true) # Hash with symbolized all keys
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
By default `ConfigDefault` using `Rails.env` to determnine what key you need from you config file.
|
|
109
109
|
You can pass this key by your own:
|
|
110
110
|
```ruby
|
|
111
|
-
config = ConfigDefault.
|
|
112
|
-
config = ConfigDefault.
|
|
111
|
+
config = ConfigDefault.hash(:app, key: nil) # Will not use key at all and result by full file
|
|
112
|
+
config = ConfigDefault.hash(:app, key: "preprod") # Will search preprod key in file
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
### `#
|
|
115
|
+
### `#struct` method
|
|
116
116
|
|
|
117
|
-
If you want to use configuration as a struct object you can use `#
|
|
117
|
+
If you want to use configuration as a struct object you can use `#struct` method.
|
|
118
118
|
Let's see an example with `database.yaml` config above:
|
|
119
119
|
|
|
120
120
|
```ruby
|
|
121
|
-
config = ConfigDefault.
|
|
121
|
+
config = ConfigDefault.struct(:database)
|
|
122
122
|
config.host
|
|
123
123
|
# => "postgres"
|
|
124
124
|
config.lolkek
|
|
125
|
-
# =>
|
|
125
|
+
# => NoMethodError
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
If your want to not raise an error on wrong key using (sometimes it's helpful) please use `allow_nil` option:
|
|
129
129
|
|
|
130
130
|
```ruby
|
|
131
|
-
config = ConfigDefault.
|
|
131
|
+
config = ConfigDefault.struct(:database, allow_nil: true)
|
|
132
132
|
config.host
|
|
133
133
|
# => "postgres"
|
|
134
134
|
config.lolkek
|
|
@@ -145,7 +145,7 @@ first:
|
|
|
145
145
|
```
|
|
146
146
|
|
|
147
147
|
```ruby
|
|
148
|
-
config = ConfigDefault.
|
|
148
|
+
config = ConfigDefault.struct(:app, key: nil, recursive: true)
|
|
149
149
|
config.first.second.third
|
|
150
150
|
# => "option"
|
|
151
151
|
```
|
|
@@ -155,7 +155,7 @@ It will be `ActiveSupport::HashWithIndifferentAccess`.
|
|
|
155
155
|
Example with `app.default.yml` from above:
|
|
156
156
|
|
|
157
157
|
```ruby
|
|
158
|
-
config = ConfigDefault.
|
|
158
|
+
config = ConfigDefault.struct(:app, key: nil, recursive: true)
|
|
159
159
|
config.to_hash
|
|
160
160
|
# => { "first" => { "second" => { "third" => "option" } } }
|
|
161
161
|
config.first.to_hash
|
|
@@ -177,7 +177,7 @@ config.first.to_hash
|
|
|
177
177
|
config.first.second.third
|
|
178
178
|
# => "option"
|
|
179
179
|
config.first.lolkek
|
|
180
|
-
# =>
|
|
180
|
+
# => NoMethodError
|
|
181
181
|
```
|
|
182
182
|
|
|
183
183
|
`ConfigDefault::Struct` supports `recursive` and `allow_nil` options.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# NOTE: Patch for #config_for method to support configuration. Used by rabbit_messaging gem
|
|
4
|
+
# https://github.com/rails/rails/blob/main/railties/lib/rails/application.rb#L295
|
|
3
5
|
module ConfigDefault::RailsApplicationConfigurationPatch
|
|
4
6
|
def load_database_yaml
|
|
5
|
-
ConfigDefault.
|
|
7
|
+
ConfigDefault.hash(:database, key: nil)
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
def database_configuration
|
|
@@ -10,9 +12,11 @@ module ConfigDefault::RailsApplicationConfigurationPatch
|
|
|
10
12
|
end
|
|
11
13
|
end
|
|
12
14
|
|
|
15
|
+
# NOTE: Patch Rails to load database configuration
|
|
16
|
+
# https://github.com/rails/rails/blob/main/railties/lib/rails/application/configuration.rb#L467
|
|
13
17
|
module ConfigDefault::RailsApplicationPatch
|
|
14
18
|
def config_for(name, env: Rails.env)
|
|
15
|
-
data = ConfigDefault.
|
|
19
|
+
data = ConfigDefault.hash(name, key: env, deep_symbolize_keys: true)
|
|
16
20
|
ActiveSupport::OrderedOptions.new.merge(data)
|
|
17
21
|
end
|
|
18
22
|
end
|
data/lib/config_default.rb
CHANGED
|
@@ -22,9 +22,9 @@ module ConfigDefault
|
|
|
22
22
|
ConfigDefault::RailsPatch.apply!
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def
|
|
26
|
-
default_config =
|
|
27
|
-
config =
|
|
25
|
+
def hash(name, key: Rails.env, symbolize_keys: false, deep_symbolize_keys: false)
|
|
26
|
+
default_config = read_file("#{name}.#{config.postfix}")
|
|
27
|
+
config = read_file(name)
|
|
28
28
|
|
|
29
29
|
if key
|
|
30
30
|
default_config = default_config[key] || {}
|
|
@@ -32,7 +32,6 @@ module ConfigDefault
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
data = default_config.deep_merge(config)
|
|
35
|
-
return {} if data.nil?
|
|
36
35
|
|
|
37
36
|
if deep_symbolize_keys
|
|
38
37
|
data.deep_symbolize_keys
|
|
@@ -43,15 +42,17 @@ module ConfigDefault
|
|
|
43
42
|
end
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
def
|
|
45
|
+
def struct(name, key: Rails.env, recursive: false, allow_nil: false)
|
|
46
|
+
attributes = hash(name, key: key)
|
|
47
|
+
ConfigDefault::Struct.new(attributes, recursive: recursive, allow_nil: allow_nil)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def read_file(name)
|
|
47
53
|
file_name = File.join(config.config_path, "#{name}.yml")
|
|
48
54
|
ActiveSupport::ConfigurationFile.parse(file_name)
|
|
49
55
|
rescue
|
|
50
56
|
{}
|
|
51
57
|
end
|
|
52
|
-
|
|
53
|
-
def load_struct(name, key: Rails.env, recursive: false, allow_nil: false)
|
|
54
|
-
attributes = load(name, key: key)
|
|
55
|
-
ConfigDefault::Struct.new(attributes, recursive: recursive, allow_nil: allow_nil)
|
|
56
|
-
end
|
|
57
58
|
end
|