fedux_org-stdlib 0.8.7 → 0.8.8

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
  SHA1:
3
- metadata.gz: 1e5236b00e36418b04fedb9fdabc64f7dff9c0ae
4
- data.tar.gz: d9883b7a10db200d561bde6567a79c281427785a
3
+ metadata.gz: f506723ed12d859cf1a77d2691967d7cf2ac3320
4
+ data.tar.gz: 3863d6a9ddcef3d63f17193fa42f1cfbe66e0656
5
5
  SHA512:
6
- metadata.gz: f0975a290e2fb2a14534a3d32a56de64039aa733b1e3dd58b248f44acfcd2502930c8e54929384bed248123beeb4a166fd7ec9417825999bba59854a40b38d21
7
- data.tar.gz: 0e2acdd1cca4c126b12e199bc8f3d8d930f137eb504f2e1225271ae5cd7a486c5a0093461d47a5dc2f1cdf410a74c67dcc418bf98c6190780d696619e686b00a
6
+ metadata.gz: c2861db382e28f365b9fc89a962efe35156389f462e83366536a82b24f22fe0164b7b84129c439f5ffe55c8f39e70338b90d35b20298286216a44988dd2f4f80
7
+ data.tar.gz: ba38b5cec4597945b9e6a40b1161d23c7acd03bd9ee19abb4c5cd79fe36579587af2da78a07515285e809a0ded8224352fab6d09cd643e354fced56fde1693e7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.8.6)
4
+ fedux_org-stdlib (0.8.7)
5
5
  activesupport
6
6
 
7
7
  PATH
@@ -180,42 +180,35 @@ module FeduxOrgStdlib
180
180
  # The config instance. If the resulting data structure created by the
181
181
  # config_engine does not respond to `:[]` an empty config object will be
182
182
  # created.
183
+
184
+ attr_reader :file, :logger, :config_engine, :check_unknown_options, :working_directory
185
+
183
186
  def initialize(
184
- file: _available_config_file,
187
+ file: nil,
185
188
  config_engine: Psych,
186
189
  logger: FeduxOrgStdlib::Logging::Logger.new,
187
- check_unknown_options: true
190
+ check_unknown_options: true,
191
+ working_directory: Dir.getwd
188
192
  )
189
- @logger = logger
190
-
191
- unless file
192
- logger.debug "No configuration file found at #{_allowed_config_file_paths.to_list}, therefor I'm going to use an empty config object instead."
193
- @__config = {}
194
-
195
- return
196
- end
197
-
198
- begin
199
- yaml = config_engine.safe_load(File.read(file), [Symbol])
200
- rescue StandardError => e
201
- raise Exceptions::ConfigFileNotReadable, JSON.dump(message: e.message, file: file)
202
- end
203
-
204
- if yaml.blank?
205
- @__config = {}
206
- elsif yaml.is_a? Hash
207
- yaml = yaml.deep_symbolize_keys
208
-
209
- yaml_withknown_options = yaml.deep_symbolize_keys.slice(*known_options)
210
- unknown_options = yaml.keys - yaml_withknown_options.keys
193
+ @logger = logger
194
+ @file = file
195
+ @config_engine = config_engine
196
+ @check_unknown_options = check_unknown_options
197
+ @working_directory = working_directory
198
+
199
+ detect_file unless @file
200
+ load_config
201
+ end
211
202
 
212
- logger.warn "Unknown config options #{(unknown_options).to_list} in config file #{file} detected. Please define them in your config class or remove the entries in your config file or disable check via `check_unknown_options: false` to get rid of this warning." unless unknown_options.blank? && check_unknown_options == true
203
+ # Reload from already found config file
204
+ def reload
205
+ load_config
206
+ end
213
207
 
214
- @__config = Hash(yaml_withknown_options)
215
- else
216
- logger.warn "There seems to be a problem transforming config file \"#{file}\" to a hash, therefor I will use an empty config object."
217
- @__config = {}
218
- end
208
+ # Redected configuration file and reload config afterwards
209
+ def redetect
210
+ detect_file
211
+ load_config
219
212
  end
220
213
 
221
214
  # Show known options for configuration
@@ -268,6 +261,42 @@ module FeduxOrgStdlib
268
261
 
269
262
  private
270
263
 
264
+ def detect_file
265
+ @file = _available_config_file
266
+ end
267
+
268
+ def load_config
269
+ unless file
270
+ logger.debug "No configuration file found at #{_allowed_config_file_paths.to_list}, therefor I'm going to use an empty config object instead."
271
+ @__config = {}
272
+
273
+ return
274
+ end
275
+
276
+ begin
277
+ yaml = config_engine.safe_load(File.read(file), [Symbol])
278
+ rescue StandardError => e
279
+ raise Exceptions::ConfigFileNotReadable, JSON.dump(message: e.message, file: file)
280
+ end
281
+
282
+ if yaml.blank?
283
+ @__config = {}
284
+ elsif yaml.is_a? Hash
285
+ yaml = yaml.deep_symbolize_keys
286
+
287
+ yaml_withknown_options = yaml.deep_symbolize_keys.slice(*known_options)
288
+ unknown_options = yaml.keys - yaml_withknown_options.keys
289
+
290
+ logger.warn "Unknown config options #{(unknown_options).to_list} in config file #{file} detected. Please define them in your config class or remove the entries in your config file or disable check via `check_unknown_options: false` to get rid of this warning." unless unknown_options.blank? && check_unknown_options == true
291
+
292
+ @__config = Hash(yaml_withknown_options)
293
+ else
294
+ logger.warn "There seems to be a problem transforming config file \"#{file}\" to a hash, therefor I will use an empty config object."
295
+ @__config = {}
296
+ end
297
+ end
298
+
299
+
271
300
  # The name of the config file
272
301
  #
273
302
  # @return [String]
@@ -334,7 +363,7 @@ module FeduxOrgStdlib
334
363
  ::File.expand_path(::File.join('~', format('.%s', _config_file))),
335
364
  ::File.expand_path(::File.join('~', format('.%src', _config_name))),
336
365
  ::File.expand_path(::File.join('/etc', _application_name, _config_file)),
337
- # ::File.expand_path("../../../../files/#{config_file}", __FILE__),
366
+ ::File.expand_path(::File.join(working_directory, _config_file))
338
367
  ]
339
368
  end
340
369
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.8.7'
4
+ VERSION = '0.8.8'
5
5
  end
@@ -395,6 +395,81 @@ RSpec.describe AppConfig do
395
395
  end
396
396
  end
397
397
 
398
+ context '#reload' do
399
+ it 're-reads it' do
400
+ config_klass = Class.new(AppConfig) do
401
+ option :opt1, 'test1'
402
+
403
+ def _class_name
404
+ 'TestConfig'
405
+ end
406
+
407
+ def _module_name
408
+ 'MyApplication'
409
+ end
410
+ end
411
+
412
+ write_file 'tests.yaml', <<-EOS.strip_heredoc
413
+ ---
414
+ opt1: test2
415
+ EOS
416
+
417
+ config = in_current_dir do
418
+ config_klass.new
419
+ end
420
+
421
+ expect(config.opt1).to eq 'test2'
422
+
423
+ write_file 'tests.yaml', <<-EOS.strip_heredoc
424
+ ---
425
+ opt1: test3
426
+ EOS
427
+
428
+ config.reload
429
+
430
+ expect(config.opt1).to eq 'test3'
431
+ end
432
+ end
433
+
434
+ context '#redetect' do
435
+ it 'looks for config file again and re-reads it' do
436
+ config_klass = Class.new(AppConfig) do
437
+ option :opt1, 'test1'
438
+
439
+ def _class_name
440
+ 'TestConfig'
441
+ end
442
+
443
+ def _module_name
444
+ 'MyApplication'
445
+ end
446
+ end
447
+
448
+ with_env 'HOME' => absolute_path('.') do
449
+ write_file 'tests.yaml', <<-EOS.strip_heredoc
450
+ ---
451
+ opt1: test2
452
+ EOS
453
+
454
+ config = in_current_dir do
455
+ config_klass.new
456
+ end
457
+
458
+ expect(config.opt1).to eq 'test2'
459
+
460
+ write_file '~/.config/my_application/tests.yaml', <<-EOS.strip_heredoc
461
+ ---
462
+ opt1: test3
463
+ EOS
464
+
465
+ config.redetect
466
+
467
+ expect(config.opt1).to eq 'test3'
468
+ end
469
+ end
470
+
471
+ end
472
+
398
473
  context '#known_options' do
399
474
  it 'outputs a list of known options' do
400
475
  with_env 'HOME' => absolute_path('.') do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport