fedux_org-stdlib 0.9.2 → 0.9.4

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: 3370153c7c20104e20c60b2078a36f7e12e1b976
4
- data.tar.gz: 6470d7d0ed4329c1a84504ba0eb8adc4bbf57658
3
+ metadata.gz: 76ef74f7ac7384488eb75228e902abeb2e21dfee
4
+ data.tar.gz: ff9585596de37c99b38737c540c254c44ef4bc78
5
5
  SHA512:
6
- metadata.gz: 5ca591fdc32795bd8e0cfb27e1dcab2c22221fc28386fd7080df617245aabf1874c2c1e51b6c589b717364aefa8de48a1613eaa259577136392071e40b645cf2
7
- data.tar.gz: c952c86471ff8c5e26590c8dc6280d585ec58aaec26bbf60a207cb37bbfe5898574d7b129221f3a864d30af8fd06ae12078c43cabaf7100dca9f1c5db081aa1f
6
+ metadata.gz: def728359046ad26adc4eacccd56600845d01ad4b1563297192506a063be05f2f1787d99ea1606b67fdb08ab1fe14704dfd01c53c765ca2dc031b06215cec838
7
+ data.tar.gz: 4adf3fb8af2604cc0dd2f296447e4f665eab7bb960430d0c7d57da3e0adbf3e4bf3064e95a1a4944a41e49b9b6b9be4d3800c205ecea073087fb70968f1bd150
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.9.1)
4
+ fedux_org-stdlib (0.9.3)
5
5
  activesupport
6
6
 
7
7
  PATH
@@ -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 to_yaml
278
- Psych.dump known_options.each_with_object({}) { |e, a| a[e.to_s] = self.public_send(e) }
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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.9.2'
4
+ VERSION = '0.9.4'
5
5
  end
@@ -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
- :test3: value3
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer