config_layers 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config_layers.gemspec +1 -1
- data/lib/config_layers/version.rb +2 -2
- data/lib/prc_core_config.rb +79 -53
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09de39566647f0ec53aeb3241730de770fbe6991
|
4
|
+
data.tar.gz: b72fa67b9d02647fac54bd0cc21dafbc8161d511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4e778e5a67f2674a065927caea04b9c48006168065da28bfc8d421a8d38c49c99f31d9337966a53ae9db3fa56458fca570f87267b5cd7547b3f2010172f9bf3
|
7
|
+
data.tar.gz: 8cdd444889903b37247d4d0127e56736846d10a6b78124637b14e0766b147d29ccc6879a0c3b01e66aa30f74f3dc836bc4e5e796b8e2259f5af52f684e03cc0a
|
data/config_layers.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "subhash", '~> 0.1.
|
22
|
+
spec.add_runtime_dependency "subhash", '~> 0.1.1'
|
23
23
|
spec.add_runtime_dependency "pry"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.9"
|
data/lib/prc_core_config.rb
CHANGED
@@ -211,7 +211,10 @@ module PRC
|
|
211
211
|
|
212
212
|
result = result.rh_merge(layer[:config][keys[0..-2]])
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
|
+
res = result[keys[-1]]
|
216
|
+
return res.merge_cleanup if [Array, Hash].include?(res.class)
|
217
|
+
res
|
215
218
|
end
|
216
219
|
|
217
220
|
# Return true if at least the first key value found is of type Hash/Array,
|
@@ -600,6 +603,72 @@ module PRC
|
|
600
603
|
|
601
604
|
config_layers[0][:config].save
|
602
605
|
end
|
606
|
+
|
607
|
+
# This function add a config layer at runtime.
|
608
|
+
# The new layer added at runtime, can be removed at runtime
|
609
|
+
# with layer_remove
|
610
|
+
# The name MUST be different than other existing config layer names
|
611
|
+
# This function is typically used by a Child Class or #layer_add.
|
612
|
+
#
|
613
|
+
# *Args*
|
614
|
+
# - +options+ : Hash data
|
615
|
+
# - :name : Required. Name of the layer to add
|
616
|
+
# - :index : Config position to use. 0 is the default. 0 is the first
|
617
|
+
# Config layer use by get.
|
618
|
+
# - :config : A Config instance of class type PRC::BaseConfig
|
619
|
+
# - :set : Boolean. True if is authorized to set a variable.
|
620
|
+
# - :load : Boolean. True if is authorized to load from a file.
|
621
|
+
# - :save : Boolean. True if is authorized to save to a file.
|
622
|
+
# - :file_set : Boolean. True if is authorized to change the file name.
|
623
|
+
#
|
624
|
+
# *returns*
|
625
|
+
# - true if layer is added.
|
626
|
+
# OR
|
627
|
+
# - nil : if layer name already exist
|
628
|
+
def p_layer_add(options)
|
629
|
+
layer = CoreConfig.define_layer(options)
|
630
|
+
|
631
|
+
layer[:init] = false # Runtime layer
|
632
|
+
|
633
|
+
index = 0
|
634
|
+
index = options[:index] if options[:index].is_a?(Fixnum)
|
635
|
+
names = []
|
636
|
+
@config_layers.each { |alayer| names << alayer[:name] }
|
637
|
+
|
638
|
+
return nil if names.include?(layer[:name])
|
639
|
+
@config_layers.insert(index, layer)
|
640
|
+
true
|
641
|
+
end
|
642
|
+
|
643
|
+
# Function to remove a runtime layer.
|
644
|
+
# You cannot remove a predefined layer, created during CoreConfig
|
645
|
+
# instanciation.
|
646
|
+
# This function is typically used by a Child Class or #layer_remove.
|
647
|
+
#
|
648
|
+
# *Args*
|
649
|
+
# - +options+ : Hash data
|
650
|
+
# - +:name+ : Name of the layer to remove.
|
651
|
+
# - +:index+: Index of the layer to remove.
|
652
|
+
#
|
653
|
+
# At least, :name or :index is required.
|
654
|
+
# If both; :name and :index are set, :name is used.
|
655
|
+
# *return*
|
656
|
+
# - true if layer name is removed.
|
657
|
+
# OR
|
658
|
+
# - nil : if not found or invalid.
|
659
|
+
def p_layer_remove(options)
|
660
|
+
index = layer_index(options[:name])
|
661
|
+
index = options[:index] if index.nil?
|
662
|
+
|
663
|
+
return nil if index.nil?
|
664
|
+
|
665
|
+
layer = @config_layers[index]
|
666
|
+
|
667
|
+
return nil if layer.nil? || layer[:init]
|
668
|
+
|
669
|
+
@config_layers.delete_at(index)
|
670
|
+
true
|
671
|
+
end
|
603
672
|
end
|
604
673
|
|
605
674
|
# private functions usable by child classes
|
@@ -662,66 +731,23 @@ module PRC
|
|
662
731
|
end
|
663
732
|
|
664
733
|
# This function add a config layer at runtime.
|
665
|
-
# The new layer added at runtime, can be removed at runtime
|
666
|
-
# with layer_remove
|
667
|
-
# The name MUST be different than other existing config layer names
|
668
734
|
#
|
669
|
-
#
|
670
|
-
#
|
671
|
-
# - :name : Required. Name of the layer to add
|
672
|
-
# - :index : Config position to use. 0 is the default. 0 is the first
|
673
|
-
# Config layer use by get.
|
674
|
-
# - :config : A Config instance of class type PRC::BaseConfig
|
675
|
-
# - :set : Boolean. True if is authorized to set a variable.
|
676
|
-
# - :load : Boolean. True if is authorized to load from a file.
|
677
|
-
# - :save : Boolean. True if is authorized to save to a file.
|
678
|
-
# - :file_set : Boolean. True if is authorized to change the file name.
|
735
|
+
# It call an internal private function #p_layer_add
|
736
|
+
# which can be used by redefined in Child class.
|
679
737
|
#
|
680
|
-
#
|
681
|
-
# - true if layer is added.
|
682
|
-
# OR
|
683
|
-
# - nil : if layer name already exist
|
738
|
+
# For options and details, see #p_layer_add
|
684
739
|
def layer_add(options)
|
685
|
-
|
686
|
-
|
687
|
-
layer[:init] = false # Runtime layer
|
688
|
-
|
689
|
-
index = 0
|
690
|
-
index = options[:index] if options[:index].is_a?(Fixnum)
|
691
|
-
names = []
|
692
|
-
@config_layers.each { |alayer| names << alayer[:name] }
|
693
|
-
|
694
|
-
return nil if names.include?(layer[:name])
|
695
|
-
@config_layers.insert(index, layer)
|
696
|
-
true
|
740
|
+
p_layer_add(options)
|
697
741
|
end
|
698
742
|
|
699
743
|
# Function to remove a runtime layer.
|
700
|
-
# You cannot remove a predefined layer, created during CoreConfig
|
701
|
-
# instanciation.
|
702
|
-
# *Args*
|
703
|
-
# - +options+ : Hash data
|
704
|
-
# - +:name+ : Name of the layer to remove.
|
705
|
-
# - +:index+: Index of the layer to remove.
|
706
744
|
#
|
707
|
-
#
|
708
|
-
#
|
709
|
-
#
|
710
|
-
#
|
711
|
-
# OR
|
712
|
-
# - nil : if not found or invalid.
|
745
|
+
# It call an internal private function #p_layer_remove
|
746
|
+
# which can be used by redefined in Child class.
|
747
|
+
#
|
748
|
+
# For options and details, see #p_layer_remove
|
713
749
|
def layer_remove(options)
|
714
|
-
|
715
|
-
index = options[:index] if index.nil?
|
716
|
-
|
717
|
-
return nil if index.nil?
|
718
|
-
|
719
|
-
layer = @config_layers[index]
|
720
|
-
|
721
|
-
return nil if layer.nil? || layer[:init]
|
722
|
-
|
723
|
-
@config_layers.delete_at(index)
|
724
|
-
true
|
750
|
+
p_layer_remove(options)
|
725
751
|
end
|
726
752
|
|
727
753
|
# Function to define layer options.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_layers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christophe Larsonneur
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: subhash
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|