config_layers 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +19 -0
- data/README.md +18 -7
- data/Rakefile +44 -7
- data/build/build_with_proxy.sh +53 -0
- data/config_layers.gemspec +11 -1
- data/files/bundle.sh +19 -0
- data/files/proxy.sh +23 -0
- data/lib/compat/1.8/prc_base_config.rb +58 -0
- data/lib/compat/1.8/prc_core_config.rb +41 -0
- data/lib/compat/1.8/prc_section_config.rb +49 -0
- data/lib/compat/prc_base_config.rb +53 -0
- data/lib/compat/prc_core_config.rb +39 -0
- data/lib/compat/prc_section_config.rb +39 -0
- data/lib/config_layers/version.rb +2 -2
- data/lib/prc_base_config.rb +14 -24
- data/lib/prc_core_config.rb +18 -23
- data/lib/prc_section_config.rb +10 -16
- metadata +54 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35335c4358c12355a1622048a3863f0e049774ce
|
4
|
+
data.tar.gz: 76cb6fee99b5c67d876778c686f7a88b98de8f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97333f0c5d53337c8566268a3f361b7bed3cd9cb76bd05240175515c2ccb95235acd8d205e793468ef88682223b489333c76359a7713f8653946687ecab57326
|
7
|
+
data.tar.gz: 00dd0251bf5c63de30df2fad4d5432dd1922be57399d2a57346f60c6f4ecf9c7db64c3e434fd5a818f4d8b628497a4a8b97c856e3b4f09e6769edc812dcdf14a
|
data/Dockerfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
FROM centos:6
|
2
|
+
|
3
|
+
COPY files/proxy.sh /tmp/proxy.sh
|
4
|
+
RUN /tmp/proxy.sh
|
5
|
+
|
6
|
+
RUN yum -y install \
|
7
|
+
libffi-devel \
|
8
|
+
libxml2-devel \
|
9
|
+
libxslt-devel \
|
10
|
+
perl \
|
11
|
+
ruby \
|
12
|
+
rubygems \
|
13
|
+
ruby-devel \
|
14
|
+
; yum -y groupinstall "Development tools" \
|
15
|
+
; yum clean all
|
16
|
+
|
17
|
+
RUN gem install --no-rdoc --no-ri bundler rake rspec && rm -fr /root/.gem
|
18
|
+
|
19
|
+
COPY files/bundle.sh /tmp/bundle.sh
|
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# ConfigLayers
|
2
2
|
|
3
|
-
ConfigLayers is a library which help to manage a complex configuration hierarchy, (Hash of Hashes/Array/...)
|
3
|
+
ConfigLayers is a library which help to manage a complex configuration hierarchy, (Hash of Hashes/Array/...)
|
4
4
|
per layers.
|
5
5
|
|
6
6
|
* What kind of complexity are we trying to resolve?
|
7
7
|
|
8
8
|
If you are using yaml or json, you can write anything in that format in some configuration file.
|
9
|
-
Ex:
|
9
|
+
Ex:
|
10
10
|
|
11
11
|
:global:
|
12
12
|
:url: http://url.example.org
|
13
|
-
:options:
|
13
|
+
:options:
|
14
14
|
:timeout: 60
|
15
15
|
:port: 4708
|
16
16
|
:application
|
@@ -28,7 +28,7 @@ per layers.
|
|
28
28
|
ConfigLayers simplify this:
|
29
29
|
|
30
30
|
- access ':timeout' :
|
31
|
-
|
31
|
+
|
32
32
|
config = PRC::BaseConfig.new(data)
|
33
33
|
|
34
34
|
timeout = config[:global, :options, :timeout]
|
@@ -42,7 +42,7 @@ per layers.
|
|
42
42
|
No need to create the Hash structure to set the ':timeout'
|
43
43
|
|
44
44
|
ConfigLayer embed YAML, so you can load and save this data from/to a yaml file...
|
45
|
-
|
45
|
+
|
46
46
|
config.save(filename)
|
47
47
|
config.load(filename)
|
48
48
|
|
@@ -65,7 +65,7 @@ per layers.
|
|
65
65
|
|
66
66
|
If the application run, with the account data loaded, when the application wants to get the timeout data
|
67
67
|
|
68
|
-
you expect to just read it! But you need to check if found in account, use it, otherwise check in user
|
68
|
+
you expect to just read it! But you need to check if found in account, use it, otherwise check in user
|
69
69
|
config, etc... until the application defaults if none of those previous configuration file has the :timeout
|
70
70
|
setting...
|
71
71
|
|
@@ -93,7 +93,7 @@ per layers.
|
|
93
93
|
|
94
94
|
initialize_layers(config_layers)
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
def define_layer(name, filename)
|
98
98
|
config = PRC::BaseConfig.new()
|
99
99
|
config.load(filename)
|
@@ -152,6 +152,17 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
152
152
|
|
153
153
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
154
154
|
|
155
|
+
## TODO:
|
156
|
+
|
157
|
+
* Replace usage of options for setting global data options to layers
|
158
|
+
the call get/set/etc... can add an 'options' parameters
|
159
|
+
This one is used to set function behavior on layers selection, setting of layers specific options
|
160
|
+
and is used as global data for layers. This introduce some misunderstanding between
|
161
|
+
config layers functions behavior and global layers behaviors.
|
162
|
+
So, we need to split these ConfigLayers and layers options by introducing
|
163
|
+
a :global_opts.
|
164
|
+
|
165
|
+
|
155
166
|
## Contributing
|
156
167
|
|
157
168
|
1. Fork it ( https://github.com/[my-github-username]/config_layers/fork )
|
data/Rakefile
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
-
require 'rubocop/rake_task'
|
3
|
+
require 'rubocop/rake_task' unless RUBY_VERSION.match(/1\.8/)
|
4
4
|
require 'rdoc/task'
|
5
|
+
require 'json'
|
5
6
|
|
6
7
|
task :default => [:lint, :spec]
|
7
8
|
|
9
|
+
desc 'Run all specs (locally + docker).'
|
10
|
+
task :spec => [:spec_local, :spec18]
|
11
|
+
|
12
|
+
desc 'Run acceptance test (docker - specs).'
|
13
|
+
task :acceptance => [:spec18]
|
14
|
+
|
8
15
|
desc 'Run the specs.'
|
9
|
-
RSpec::Core::RakeTask.new do |t|
|
16
|
+
RSpec::Core::RakeTask.new(:spec_local) do |t|
|
10
17
|
t.pattern = 'spec/*_spec.rb'
|
11
18
|
t.rspec_opts = '-f doc'
|
12
19
|
end
|
@@ -17,11 +24,41 @@ RDoc::Task.new do |rdoc|
|
|
17
24
|
rdoc.rdoc_files.include('README.md', 'lib', 'example', 'bin')
|
18
25
|
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
task
|
23
|
-
|
24
|
-
|
27
|
+
if RUBY_VERSION.match(/1\.8/)
|
28
|
+
desc 'no lint with ruby 1.8'
|
29
|
+
task :lint
|
30
|
+
else
|
31
|
+
desc 'Run RuboCop on the project'
|
32
|
+
RuboCop::RakeTask.new(:lint) do |task|
|
33
|
+
task.formatters = ['progress']
|
34
|
+
task.verbose = true
|
35
|
+
task.fail_on_error = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# rubocop: disable Style/SpecialGlobalVars
|
40
|
+
|
41
|
+
desc 'Run spec with docker for ruby 1.8'
|
42
|
+
task :spec18 do
|
43
|
+
begin
|
44
|
+
`docker`
|
45
|
+
rescue
|
46
|
+
puts 'Unable to run spec against ruby 1.8: docker not found'
|
47
|
+
else
|
48
|
+
system('build/build_with_proxy.sh -t ruby/1.8')
|
49
|
+
image_id = `docker images ruby/1.8`.split("\n")[1].split[2]
|
50
|
+
res = `docker inspect -f '{{json .}}' config_layers`
|
51
|
+
c_img = ''
|
52
|
+
c_img = JSON.parse(res)['Image'][0..11] if $?.exitstatus == 0
|
53
|
+
|
54
|
+
if $?.exitstatus == 0 && image_id == c_img
|
55
|
+
system('docker start -ai config_layers')
|
56
|
+
else
|
57
|
+
`docker rm config_layers` if $?.exitstatus == 0
|
58
|
+
system('docker run -it --name config_layers -v '\
|
59
|
+
'$(pwd):/src -w /src ruby/1.8 /tmp/bundle.sh')
|
60
|
+
end
|
61
|
+
end
|
25
62
|
end
|
26
63
|
|
27
64
|
task :build => [:lint, :spec]
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
function usage
|
18
|
+
{
|
19
|
+
echo "usage is $0 [--help][-t user/repo:version]
|
20
|
+
Script to build a docker image.
|
21
|
+
It takes your local setting of $http_proxy to build the image with the same proxy
|
22
|
+
If the proxy is not set, the docker image is simply executed, without proxy.
|
23
|
+
|
24
|
+
Options :
|
25
|
+
- help: is the current help
|
26
|
+
- t : Tag the image built. Respect the tag format use by docker -t option.
|
27
|
+
"
|
28
|
+
}
|
29
|
+
|
30
|
+
if [ "p$1" = "p--help" ]
|
31
|
+
then
|
32
|
+
usage
|
33
|
+
exit
|
34
|
+
fi
|
35
|
+
|
36
|
+
if [ "p$1" = "p-t" ] && [ "p$2" != "" ]
|
37
|
+
then
|
38
|
+
TAG="-t $2"
|
39
|
+
fi
|
40
|
+
|
41
|
+
if [ "$http_proxy" = "" ]
|
42
|
+
then
|
43
|
+
echo "Currently, no proxy is set. Running docker without proxy"
|
44
|
+
docker build $TAG
|
45
|
+
exit
|
46
|
+
fi
|
47
|
+
|
48
|
+
mkdir .tmp
|
49
|
+
awk '$0 ~ /RUN \/tmp\/proxy.sh/ { print "ENV http_proxy '"$http_proxy"'" }
|
50
|
+
$0 ~ // { print $0 } ' Dockerfile > .tmp/Dockerfile
|
51
|
+
cp -rp files tmp .tmp/
|
52
|
+
docker build $TAG .tmp
|
53
|
+
rm -fr .tmp
|
data/config_layers.gemspec
CHANGED
@@ -21,9 +21,19 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "subhash", '~> 0.1.1'
|
23
23
|
spec.add_runtime_dependency "pry"
|
24
|
+
spec.add_runtime_dependency "json"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.9"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
28
|
spec.add_development_dependency "rspec", "~> 3.1.0"
|
28
|
-
spec.add_development_dependency "
|
29
|
+
spec.add_development_dependency "rdoc"
|
30
|
+
if RUBY_VERSION.match(/1\.8/)
|
31
|
+
spec.add_development_dependency "ruby-debug"
|
32
|
+
elsif RUBY_VERSION.match(/1\.9/)
|
33
|
+
spec.add_development_dependency "debugger"
|
34
|
+
spec.add_development_dependency "rubocop", "~> 0.30.0"
|
35
|
+
else
|
36
|
+
spec.add_development_dependency "byebug"
|
37
|
+
spec.add_development_dependency "rubocop", "~> 0.30.0"
|
38
|
+
end
|
29
39
|
end
|
data/files/bundle.sh
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
cd /src
|
18
|
+
bundle
|
19
|
+
rake spec_local
|
data/files/proxy.sh
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
if [ "$http_proxy" != "" ]
|
18
|
+
then
|
19
|
+
echo "proxy setting to '$http_proxy'"
|
20
|
+
export http_proxy=$http_proxy
|
21
|
+
export https_proxy=$http_proxy
|
22
|
+
sed -i -e '/^\[main\]/aproxy='"$http_proxy" /etc/yum.conf
|
23
|
+
fi
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#--
|
2
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
#
|
18
|
+
module PRC
|
19
|
+
# Specific Ruby1.8 functions
|
20
|
+
# Those files can be removed as soon as compatibility won't be required
|
21
|
+
module BaseConfigRubySpec
|
22
|
+
# Public functions
|
23
|
+
module Public
|
24
|
+
# Set function
|
25
|
+
#
|
26
|
+
# * *Args*
|
27
|
+
# - +*prop+ : from *prop, is a combination:
|
28
|
+
# - *keys : Keys where to set value.
|
29
|
+
# - value : value to set.
|
30
|
+
#
|
31
|
+
# * *Returns*
|
32
|
+
# - The value set or nil
|
33
|
+
#
|
34
|
+
# ex:
|
35
|
+
# value = CoreConfig.New
|
36
|
+
#
|
37
|
+
# value[:level1, :level2] = 'value'
|
38
|
+
# # => {:level1 => {:level2 => 'value'}}
|
39
|
+
def []=(*prop)
|
40
|
+
p_set(*prop)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Private functions
|
45
|
+
module Private
|
46
|
+
#
|
47
|
+
def p_set(*prop)
|
48
|
+
keys = prop.clone
|
49
|
+
value = keys.pop
|
50
|
+
|
51
|
+
return nil if keys.length == 0
|
52
|
+
return p_get(*keys) if @data_options[:data_readonly]
|
53
|
+
|
54
|
+
@data.rh_set(value, keys)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module PRC
|
18
|
+
# Specific ALL Ruby functions, but incompatible with some other version.
|
19
|
+
module CoreConfigRubySpec
|
20
|
+
# Public functions
|
21
|
+
module Public
|
22
|
+
# Set function
|
23
|
+
#
|
24
|
+
# * *Args*
|
25
|
+
# - +keys+ : Array of key path to found
|
26
|
+
# * *Returns*
|
27
|
+
# - The value set or nil
|
28
|
+
#
|
29
|
+
# ex:
|
30
|
+
# value = CoreConfig.New
|
31
|
+
#
|
32
|
+
# value[:level1, :level2] = 'value'
|
33
|
+
# # => {:level1 => {:level2 => 'value'}}
|
34
|
+
def []=(*prop)
|
35
|
+
keys = prop.clone
|
36
|
+
value = keys.pop
|
37
|
+
p_set(:keys => keys, :value => value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module PRC
|
18
|
+
# Specific ALL Ruby functions, but incompatible with some other version.
|
19
|
+
module SectionConfigRubySpec
|
20
|
+
# Public functions
|
21
|
+
module Public
|
22
|
+
# Set the value of a specific key under a section.
|
23
|
+
# You have to call #data_options(:section => 'MySection')
|
24
|
+
#
|
25
|
+
# * *Args* :
|
26
|
+
# - +keys+ : keys to get values from a section set by data_options.
|
27
|
+
# If section is not set, it will use :default
|
28
|
+
# * *Returns* :
|
29
|
+
# - key value.
|
30
|
+
# * *Raises* :
|
31
|
+
# Nothing
|
32
|
+
def []=(*prop)
|
33
|
+
keys = prop.clone
|
34
|
+
value = keys.pop
|
35
|
+
|
36
|
+
return nil if keys.length == 0
|
37
|
+
|
38
|
+
if @data_options[:section].nil?
|
39
|
+
par = [:default]
|
40
|
+
else
|
41
|
+
par = [@data_options[:section]]
|
42
|
+
end
|
43
|
+
par += keys
|
44
|
+
par << value
|
45
|
+
p_set(*par)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#--
|
2
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
#
|
18
|
+
module PRC
|
19
|
+
# Specific ALL Ruby functions, but incompatible with some other version.
|
20
|
+
module BaseConfigRubySpec
|
21
|
+
# Public functions
|
22
|
+
module Public
|
23
|
+
# Set function
|
24
|
+
#
|
25
|
+
# * *Args*
|
26
|
+
# - *keys : Keys where to set value.
|
27
|
+
# - value : value to set.
|
28
|
+
#
|
29
|
+
# * *Returns*
|
30
|
+
# - The value set or nil
|
31
|
+
#
|
32
|
+
# ex:
|
33
|
+
# value = CoreConfig.New
|
34
|
+
#
|
35
|
+
# value[:level1, :level2] = 'value'
|
36
|
+
# # => {:level1 => {:level2 => 'value'}}
|
37
|
+
def []=(*keys, value)
|
38
|
+
p_set(*keys, value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Private functions
|
43
|
+
module Private
|
44
|
+
#
|
45
|
+
def p_set(*keys, value)
|
46
|
+
return nil if keys.length == 0
|
47
|
+
return p_get(*keys) if @data_options[:data_readonly]
|
48
|
+
|
49
|
+
@data.rh_set(value, keys)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module PRC
|
18
|
+
# Specific ALL Ruby functions, but incompatible with some other version.
|
19
|
+
module CoreConfigRubySpec
|
20
|
+
# Public functions
|
21
|
+
module Public
|
22
|
+
# Set function
|
23
|
+
#
|
24
|
+
# * *Args*
|
25
|
+
# - +keys+ : Array of key path to found
|
26
|
+
# * *Returns*
|
27
|
+
# - The value set or nil
|
28
|
+
#
|
29
|
+
# ex:
|
30
|
+
# value = CoreConfig.New
|
31
|
+
#
|
32
|
+
# value[:level1, :level2] = 'value'
|
33
|
+
# # => {:level1 => {:level2 => 'value'}}
|
34
|
+
def []=(*keys, value)
|
35
|
+
p_set(:keys => keys, :value => value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module PRC
|
18
|
+
# Specific ALL Ruby functions, but incompatible with some other version.
|
19
|
+
module SectionConfigRubySpec
|
20
|
+
# Public functions
|
21
|
+
module Public
|
22
|
+
# Set the value of a specific key under a section.
|
23
|
+
# You have to call #data_options(:section => 'MySection')
|
24
|
+
#
|
25
|
+
# * *Args* :
|
26
|
+
# - +keys+ : keys to get values from a section set by data_options.
|
27
|
+
# If section is not set, it will use :default
|
28
|
+
# * *Returns* :
|
29
|
+
# - key value.
|
30
|
+
# * *Raises* :
|
31
|
+
# Nothing
|
32
|
+
def []=(*keys, value)
|
33
|
+
return nil if keys.length == 0
|
34
|
+
return p_set(:default, *keys, value) if @data_options[:section].nil?
|
35
|
+
p_set(@data_options[:section], *keys, value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/prc_base_config.rb
CHANGED
@@ -16,6 +16,14 @@
|
|
16
16
|
|
17
17
|
require 'yaml'
|
18
18
|
|
19
|
+
file_dir = File.join(File.dirname(__FILE__), 'compat')
|
20
|
+
compat_version = RUBY_VERSION[0..2]
|
21
|
+
file = File.basename(__FILE__)
|
22
|
+
|
23
|
+
lib = File.join(file_dir, compat_version, file)
|
24
|
+
lib = File.join(file_dir, file) unless File.exist?(lib)
|
25
|
+
load lib if File.exist?(lib)
|
26
|
+
|
19
27
|
module PRC
|
20
28
|
# This class is Base config system of lorj.
|
21
29
|
#
|
@@ -162,23 +170,6 @@ module PRC
|
|
162
170
|
p_del(*keys)
|
163
171
|
end
|
164
172
|
|
165
|
-
# Set function
|
166
|
-
#
|
167
|
-
# * *Args*
|
168
|
-
# - +keys+ : set a value in the Array of key path.
|
169
|
-
#
|
170
|
-
# * *Returns*
|
171
|
-
# - The value set or nil
|
172
|
-
#
|
173
|
-
# ex:
|
174
|
-
# value = CoreConfig.New
|
175
|
-
#
|
176
|
-
# value[:level1, :level2] = 'value'
|
177
|
-
# # => {:level1 => {:level2 => 'value'}}
|
178
|
-
def []=(*keys, value)
|
179
|
-
p_set(*keys, value)
|
180
|
-
end
|
181
|
-
|
182
173
|
# Load from a file
|
183
174
|
#
|
184
175
|
# * *Args* :
|
@@ -266,6 +257,9 @@ module PRC
|
|
266
257
|
(@version == @latest_version)
|
267
258
|
end
|
268
259
|
|
260
|
+
# Load specific Ruby versionned code.
|
261
|
+
include PRC::BaseConfigRubySpec::Public
|
262
|
+
|
269
263
|
private
|
270
264
|
|
271
265
|
def p_data_options(options = nil)
|
@@ -291,13 +285,6 @@ module PRC
|
|
291
285
|
@data.rh_del(*keys)
|
292
286
|
end
|
293
287
|
|
294
|
-
def p_set(*keys, value)
|
295
|
-
return nil if keys.length == 0
|
296
|
-
return p_get(*keys) if @data_options[:data_readonly]
|
297
|
-
|
298
|
-
@data.rh_set(value, keys)
|
299
|
-
end
|
300
|
-
|
301
288
|
def p_load(file = nil)
|
302
289
|
self.filename = file unless file.nil?
|
303
290
|
|
@@ -327,5 +314,8 @@ module PRC
|
|
327
314
|
File.open(@filename, 'w+') { |out| YAML.dump(@data_dup, out) }
|
328
315
|
true
|
329
316
|
end
|
317
|
+
|
318
|
+
# Load specific Ruby versionned code.
|
319
|
+
include PRC::BaseConfigRubySpec::Private
|
330
320
|
end
|
331
321
|
end
|
data/lib/prc_core_config.rb
CHANGED
@@ -16,6 +16,14 @@
|
|
16
16
|
|
17
17
|
require 'yaml'
|
18
18
|
|
19
|
+
file_dir = File.join(File.dirname(__FILE__), 'compat')
|
20
|
+
compat_version = RUBY_VERSION[0..2]
|
21
|
+
file = File.basename(__FILE__)
|
22
|
+
|
23
|
+
lib = File.join(file_dir, compat_version, file)
|
24
|
+
lib = File.join(file_dir, file) unless File.exist?(lib)
|
25
|
+
load lib if File.exist?(lib)
|
26
|
+
|
19
27
|
module PRC
|
20
28
|
# Internal CoreConfig functions
|
21
29
|
class CoreConfig
|
@@ -266,7 +274,7 @@ module PRC
|
|
266
274
|
# - +:index+ : layer index to get data.
|
267
275
|
# If neither :name or :index is set, set will use the
|
268
276
|
# highest layer
|
269
|
-
# - +:data_opts+
|
277
|
+
# - +:data_opts+ : Array or Hash. Define data options per layer.
|
270
278
|
#
|
271
279
|
# * *Returns*
|
272
280
|
# - The value attached to the key deleted.
|
@@ -290,12 +298,13 @@ module PRC
|
|
290
298
|
|
291
299
|
config_layers, data_opts, keys = parameters[0]
|
292
300
|
|
301
|
+
# TODO: Replace usage of options for setting global data options to layers
|
293
302
|
# get data options for level 0
|
294
303
|
data_options = options.clone.merge!(data_opts[0])
|
295
304
|
|
296
305
|
return nil if keys.length == 0
|
297
306
|
|
298
|
-
data_options.delete_if do |key|
|
307
|
+
data_options.delete_if do |key, _|
|
299
308
|
[:keys, :names, :indexes, :name, :index].include?(key)
|
300
309
|
end
|
301
310
|
|
@@ -381,7 +390,7 @@ module PRC
|
|
381
390
|
config = config_layers[index][:config]
|
382
391
|
|
383
392
|
data_options = options.clone
|
384
|
-
data_options.delete_if do |key|
|
393
|
+
data_options.delete_if do |key, _|
|
385
394
|
[:keys, :names, :indexes, :name, :index].include?(key)
|
386
395
|
end
|
387
396
|
data_options.merge!(data_opts[index])
|
@@ -427,7 +436,7 @@ module PRC
|
|
427
436
|
config = config_layers[index][:config]
|
428
437
|
|
429
438
|
data_options = options.clone
|
430
|
-
data_options.delete_if do |key|
|
439
|
+
data_options.delete_if do |key, _|
|
431
440
|
[:keys, :names, :indexes, :name, :index].include?(key)
|
432
441
|
end
|
433
442
|
data_options.merge!(data_opts[index]) if data_opts[index].is_a?(Hash)
|
@@ -491,7 +500,7 @@ module PRC
|
|
491
500
|
return nil if keys.length == 0 || keys[0].nil? || config_layers[0].nil?
|
492
501
|
|
493
502
|
data_options = options.clone
|
494
|
-
data_options.delete_if do |key|
|
503
|
+
data_options.delete_if do |key, _|
|
495
504
|
[:keys, :names, :indexes, :name, :index, :merge].include?(key)
|
496
505
|
end
|
497
506
|
|
@@ -538,7 +547,7 @@ module PRC
|
|
538
547
|
|
539
548
|
return nil if keys.length == 0 || keys[0].nil? || config_layers[0].nil?
|
540
549
|
|
541
|
-
data_options.delete_if do |key|
|
550
|
+
data_options.delete_if do |key, _|
|
542
551
|
[:keys, :names, :indexes, :name, :index, :value].include?(key)
|
543
552
|
end
|
544
553
|
|
@@ -1056,22 +1065,6 @@ module PRC
|
|
1056
1065
|
p_get(:keys => keys, :merge => true)
|
1057
1066
|
end
|
1058
1067
|
|
1059
|
-
# Set function
|
1060
|
-
#
|
1061
|
-
# * *Args*
|
1062
|
-
# - +keys+ : Array of key path to found
|
1063
|
-
# * *Returns*
|
1064
|
-
# - The value set or nil
|
1065
|
-
#
|
1066
|
-
# ex:
|
1067
|
-
# value = CoreConfig.New
|
1068
|
-
#
|
1069
|
-
# value[:level1, :level2] = 'value'
|
1070
|
-
# # => {:level1 => {:level2 => 'value'}}
|
1071
|
-
def []=(*keys, value)
|
1072
|
-
p_set(:keys => keys, :value => value)
|
1073
|
-
end
|
1074
|
-
|
1075
1068
|
# Del function
|
1076
1069
|
#
|
1077
1070
|
# * *Args*
|
@@ -1166,7 +1159,7 @@ module PRC
|
|
1166
1159
|
return nil if keys.length == 0 || keys[0].nil? || config_layers[0].nil?
|
1167
1160
|
|
1168
1161
|
data_options = options.clone
|
1169
|
-
data_options.delete_if do |key|
|
1162
|
+
data_options.delete_if do |key, _|
|
1170
1163
|
[:keys, :names, :indexes, :name, :index, :merge].include?(key)
|
1171
1164
|
end
|
1172
1165
|
|
@@ -1235,6 +1228,8 @@ module PRC
|
|
1235
1228
|
data
|
1236
1229
|
end
|
1237
1230
|
|
1231
|
+
include PRC::CoreConfigRubySpec::Public
|
1232
|
+
|
1238
1233
|
private
|
1239
1234
|
|
1240
1235
|
def to_s_file_opts(layer)
|
data/lib/prc_section_config.rb
CHANGED
@@ -17,6 +17,14 @@
|
|
17
17
|
require 'rubygems'
|
18
18
|
require 'yaml'
|
19
19
|
|
20
|
+
file_dir = File.join(File.dirname(__FILE__), 'compat')
|
21
|
+
compat_version = RUBY_VERSION[0..2]
|
22
|
+
file = File.basename(__FILE__)
|
23
|
+
|
24
|
+
lib = File.join(file_dir, compat_version, file)
|
25
|
+
lib = File.join(file_dir, file) unless File.exist?(lib)
|
26
|
+
load lib if File.exist?(lib)
|
27
|
+
|
20
28
|
module PRC
|
21
29
|
# SectionConfig class layer based on BaseConfig.
|
22
30
|
#
|
@@ -39,22 +47,6 @@ module PRC
|
|
39
47
|
p_get(@data_options[:section], *keys)
|
40
48
|
end
|
41
49
|
|
42
|
-
# Set the value of a specific key under a section.
|
43
|
-
# You have to call #data_options(:section => 'MySection')
|
44
|
-
#
|
45
|
-
# * *Args* :
|
46
|
-
# - +keys+ : keys to get values from a section set by data_options.
|
47
|
-
# If section is not set, it will use :default
|
48
|
-
# * *Returns* :
|
49
|
-
# - key value.
|
50
|
-
# * *Raises* :
|
51
|
-
# Nothing
|
52
|
-
def []=(*keys, value)
|
53
|
-
return nil if keys.length == 0
|
54
|
-
return p_set(:default, *keys, value) if @data_options[:section].nil?
|
55
|
-
p_set(@data_options[:section], *keys, value)
|
56
|
-
end
|
57
|
-
|
58
50
|
# Check key existence under a section.
|
59
51
|
# You have to call #data_options(:section => 'MySection')
|
60
52
|
#
|
@@ -86,6 +78,8 @@ module PRC
|
|
86
78
|
return p_del(:default, *keys) if @data_options[:section].nil?
|
87
79
|
p_del(@data_options[:section], *keys)
|
88
80
|
end
|
81
|
+
|
82
|
+
include PRC::SectionConfigRubySpec::Public
|
89
83
|
end
|
90
84
|
|
91
85
|
# SectionsConfig class layer based on SectionConfig.
|
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.4
|
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-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: subhash
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,34 @@ dependencies:
|
|
80
94
|
- - ~>
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: 3.1.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rdoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: rubocop
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,12 +147,22 @@ files:
|
|
105
147
|
- .gitreview
|
106
148
|
- .rspec
|
107
149
|
- .rubocop.yml
|
150
|
+
- Dockerfile
|
108
151
|
- Gemfile
|
109
152
|
- README.md
|
110
153
|
- Rakefile
|
111
154
|
- bin/console
|
112
155
|
- bin/setup
|
156
|
+
- build/build_with_proxy.sh
|
113
157
|
- config_layers.gemspec
|
158
|
+
- files/bundle.sh
|
159
|
+
- files/proxy.sh
|
160
|
+
- lib/compat/1.8/prc_base_config.rb
|
161
|
+
- lib/compat/1.8/prc_core_config.rb
|
162
|
+
- lib/compat/1.8/prc_section_config.rb
|
163
|
+
- lib/compat/prc_base_config.rb
|
164
|
+
- lib/compat/prc_core_config.rb
|
165
|
+
- lib/compat/prc_section_config.rb
|
114
166
|
- lib/config_layers.rb
|
115
167
|
- lib/config_layers/version.rb
|
116
168
|
- lib/prc_base_config.rb
|