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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db6708e562f296b9fc30108bfccaedf20958ec2f1854f78340469a3bc5305c82
4
- data.tar.gz: 52e89e977db9e4e84c77474c9293a49bd7221a31e4332a63cb46d3a0c0753fee
3
+ metadata.gz: 64815caf5e319e0a0450d51ffcec8e2e90358cad44ea56b96810f05ff7376a4f
4
+ data.tar.gz: 37412fc1357aa64d689bc94310b2208a1b2f120f91a303fb9b2700398fb65110
5
5
  SHA512:
6
- metadata.gz: 362be41b678e92605b275f821e7b600455e46cba0eb35dbd2cddf2440de97e1c26b92ba4cca86cb194c5df2376cf4f001ea1096339721c1b51e3c52fabb3c3a7
7
- data.tar.gz: e607fab179b3aa0ccf9906ad426c158b812736cac16cc07e17aff4963096e68cad1d66141a884a796af30ba6d3fe66d82dc9623ae2e51edf7386c0f4390a0c02
6
+ metadata.gz: e867d8bed4ce7d7fcbd9b0ff5101cb9049954cb69b3212cdba2f891db5c36ab3799fe25997e7a81a0d94b9bcdfe0e6bb5988086537eb37e7ba68fcad05cbb157
7
+ data.tar.gz: 6d1b4e3b838952deb21db1cbddea070703d2737e922db0b2c27c86c795f74c67e075c02cfbc532b8520c1d6279720bc598618d87443c45d02ca7d4fc6e6a8be3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.5.4
2
+ - Upgrade gems.
3
+ - Rename #load to #hash
4
+ - Rename #load_struct to #struct
5
+ - Change ArgumentError to NoMethodError (call super)
6
+ - Make #read_file method private
7
+
1
8
  ## 0.5.2
2
9
 
3
10
  - Upgrade to ruby & gems.
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- config_default (0.5.3)
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.16)
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.1)
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.18.1)
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.0)
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.1)
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.1-arm64-darwin)
136
+ nokogiri (1.19.2-arm64-darwin)
136
137
  racc (~> 1.4)
137
- nokogiri (1.19.1-x86_64-darwin)
138
+ nokogiri (1.19.2-x86_64-darwin)
138
139
  racc (~> 1.4)
139
- nokogiri (1.19.1-x86_64-linux-gnu)
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.6.2)
184
- loofah (~> 2.21)
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.7)
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.82.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.48.0, < 2.0)
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.0)
229
+ rubocop-ast (1.49.1)
229
230
  parser (>= 3.3.7.2)
230
231
  prism (~> 1.7)
231
- rubocop-config-umbrellio (1.82.117)
232
- rubocop (~> 1.82.0)
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.0)
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.4)
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.load(:app)
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.load(:app, symbolize_keys: true) # Hash with symbolized first keys
105
- config = ConfigDefault.load(:app, deep_symbolize_keys: true) # Hash with symbolized all keys
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.load(:app, key: nil) # Will not use key at all and result by full file
112
- config = ConfigDefault.load(:app, key: "preprod") # Will search preprod key in file
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
- ### `#load_struct` method
115
+ ### `#struct` method
116
116
 
117
- If you want to use configuration as a struct object you can use `#load_struct` method.
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.load_struct(:database)
121
+ config = ConfigDefault.struct(:database)
122
122
  config.host
123
123
  # => "postgres"
124
124
  config.lolkek
125
- # => StandardError: There is no option :lolkek in configuration.
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.load_struct(:database, allow_nil: true)
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.load_struct(:app, key: nil, recursive: true)
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.load_struct(:app, key: nil, recursive: true)
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
- # => StandardError: There is no option :lolkek in configuration.
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.load(:database, key: nil)
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.load(name, key: env, deep_symbolize_keys: true)
19
+ data = ConfigDefault.hash(name, key: env, deep_symbolize_keys: true)
16
20
  ActiveSupport::OrderedOptions.new.merge(data)
17
21
  end
18
22
  end
@@ -20,7 +20,7 @@ class ConfigDefault::Struct
20
20
 
21
21
  def method_missing(method, *_args)
22
22
  return if @allow_nil
23
- raise ArgumentError.new("There is no option :#{method} in configuration.")
23
+ super
24
24
  end
25
25
 
26
26
  def respond_to_missing?(*_args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConfigDefault
4
- VERSION = "0.5.3"
4
+ VERSION = "0.5.4"
5
5
  end
@@ -22,9 +22,9 @@ module ConfigDefault
22
22
  ConfigDefault::RailsPatch.apply!
23
23
  end
24
24
 
25
- def load(name, key: Rails.env, symbolize_keys: false, deep_symbolize_keys: false)
26
- default_config = load_file("#{name}.#{config.postfix}")
27
- config = load_file(name)
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 load_file(name)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_default
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stepan Kirushkin