fedux_org-stdlib 0.9.2 → 0.9.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/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/app_config.rb +7 -3
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/app_config_spec.rb +97 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76ef74f7ac7384488eb75228e902abeb2e21dfee
|
|
4
|
+
data.tar.gz: ff9585596de37c99b38737c540c254c44ef4bc78
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: def728359046ad26adc4eacccd56600845d01ad4b1563297192506a063be05f2f1787d99ea1606b67fdb08ab1fe14704dfd01c53c765ca2dc031b06215cec838
|
|
7
|
+
data.tar.gz: 4adf3fb8af2604cc0dd2f296447e4f665eab7bb960430d0c7d57da3e0adbf3e4bf3064e95a1a4944a41e49b9b6b9be4d3800c205ecea073087fb70968f1bd150
|
data/Gemfile.lock
CHANGED
|
@@ -5,7 +5,7 @@ require 'fedux_org_stdlib/process_environment'
|
|
|
5
5
|
require 'fedux_org_stdlib/core_ext/array/list'
|
|
6
6
|
require 'fedux_org_stdlib/core_ext/hash/list'
|
|
7
7
|
require 'fedux_org_stdlib/logging/logger'
|
|
8
|
-
require_library %w(json psych active_support/core_ext/string/inflections set active_support/core_ext/hash/slice active_support/core_ext/object/blank active_support/core_ext/hash/keys)
|
|
8
|
+
require_library %w(json psych active_support/core_ext/hash/keys active_support/core_ext/string/inflections set active_support/core_ext/hash/slice active_support/core_ext/object/blank active_support/core_ext/hash/keys)
|
|
9
9
|
|
|
10
10
|
module FeduxOrgStdlib
|
|
11
11
|
# This class makes a config file available as an object. The config file
|
|
@@ -274,8 +274,12 @@ module FeduxOrgStdlib
|
|
|
274
274
|
config
|
|
275
275
|
end
|
|
276
276
|
|
|
277
|
-
def
|
|
278
|
-
|
|
277
|
+
def to_h(keys: known_options.to_a)
|
|
278
|
+
known_options.keep_if { |o| keys.include? o }.each_with_object({}) { |e, a| a[e] = self.public_send(e) }
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def to_yaml(**args)
|
|
282
|
+
Psych.dump to_h(**args).deep_stringify_keys
|
|
279
283
|
end
|
|
280
284
|
|
|
281
285
|
private
|
data/spec/app_config_spec.rb
CHANGED
|
@@ -480,6 +480,71 @@ RSpec.describe AppConfig do
|
|
|
480
480
|
end
|
|
481
481
|
end
|
|
482
482
|
|
|
483
|
+
context '#to_h' do
|
|
484
|
+
it 'dumps configuration to hash' do
|
|
485
|
+
config_klass = Class.new(AppConfig) do
|
|
486
|
+
option :opt1, 'test1'
|
|
487
|
+
|
|
488
|
+
option :opt2, [
|
|
489
|
+
'test2',
|
|
490
|
+
'test2',
|
|
491
|
+
]
|
|
492
|
+
|
|
493
|
+
option :opt3, {
|
|
494
|
+
test3: 'value3'
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
def _class_name
|
|
498
|
+
'TestConfig'
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
def _module_name
|
|
502
|
+
'MyApplication'
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
config = config_klass.new
|
|
507
|
+
expect(config.to_h).to eq(
|
|
508
|
+
opt1: 'test1',
|
|
509
|
+
opt2: %w(
|
|
510
|
+
test2
|
|
511
|
+
test2
|
|
512
|
+
),
|
|
513
|
+
opt3: {
|
|
514
|
+
test3: 'value3'
|
|
515
|
+
}
|
|
516
|
+
)
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
it 'filters keys' do
|
|
520
|
+
config_klass = Class.new(AppConfig) do
|
|
521
|
+
option :opt1, 'test1'
|
|
522
|
+
|
|
523
|
+
option :opt2, [
|
|
524
|
+
'test2',
|
|
525
|
+
'test2',
|
|
526
|
+
]
|
|
527
|
+
|
|
528
|
+
option :opt3, {
|
|
529
|
+
test3: 'value3'
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
def _class_name
|
|
533
|
+
'TestConfig'
|
|
534
|
+
end
|
|
535
|
+
|
|
536
|
+
def _module_name
|
|
537
|
+
'MyApplication'
|
|
538
|
+
end
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
config = config_klass.new
|
|
542
|
+
expect(config.to_h(keys: [:opt1])).to eq(
|
|
543
|
+
opt1: 'test1'
|
|
544
|
+
)
|
|
545
|
+
end
|
|
546
|
+
end
|
|
547
|
+
|
|
483
548
|
context '#to_yaml' do
|
|
484
549
|
it 'dumps configuration to yaml' do
|
|
485
550
|
config_klass = Class.new(AppConfig) do
|
|
@@ -511,7 +576,38 @@ RSpec.describe AppConfig do
|
|
|
511
576
|
- test2
|
|
512
577
|
- test2
|
|
513
578
|
opt3:
|
|
514
|
-
|
|
579
|
+
test3: value3
|
|
580
|
+
EOS
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
it 'filters keys' do
|
|
584
|
+
config_klass = Class.new(AppConfig) do
|
|
585
|
+
option :opt1, 'test1'
|
|
586
|
+
|
|
587
|
+
option :opt2, [
|
|
588
|
+
'test2',
|
|
589
|
+
'test2',
|
|
590
|
+
]
|
|
591
|
+
|
|
592
|
+
option :opt3, {
|
|
593
|
+
test3: 'value3'
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
def _class_name
|
|
597
|
+
'TestConfig'
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
def _module_name
|
|
601
|
+
'MyApplication'
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
config = config_klass.new
|
|
606
|
+
expect(
|
|
607
|
+
config.to_yaml(keys: [:opt1])
|
|
608
|
+
).to eq <<-EOS.strip_heredoc
|
|
609
|
+
---
|
|
610
|
+
opt1: test1
|
|
515
611
|
EOS
|
|
516
612
|
end
|
|
517
613
|
end
|