config_layers 0.1.0

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.
@@ -0,0 +1,90 @@
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
+ require 'rubygems'
18
+ require 'yaml'
19
+
20
+ module PRC
21
+ # SectionConfig class layer based on BaseConfig.
22
+ #
23
+ # It supports a data_options :section for #[], #[]=, etc...
24
+ #
25
+ class SectionConfig < PRC::BaseConfig
26
+ # Get the value of a specific key under a section.
27
+ # You have to call #data_options(:section => 'MySection')
28
+ #
29
+ # * *Args* :
30
+ # - +keys+ : keys to get values from a section set by data_options.
31
+ # If section is not set, it will use :default
32
+ # * *Returns* :
33
+ # - key value.
34
+ # * *Raises* :
35
+ # Nothing
36
+ def [](*keys)
37
+ return nil if keys.length == 0
38
+ return p_get(:default, *keys) if @data_options[:section].nil?
39
+ p_get(@data_options[:section], *keys)
40
+ end
41
+
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
+ # Check key existence under a section.
59
+ # You have to call #data_options(:section => 'MySection')
60
+ #
61
+ # * *Args* :
62
+ # - +keys+ : keys to get values from a section set by data_options.
63
+ # If section is not set, it will use :default
64
+ # * *Returns* :
65
+ # - key value.
66
+ # * *Raises* :
67
+ # Nothing
68
+ def exist?(*keys)
69
+ return nil if keys.length == 0
70
+ return p_exist?(:default, *keys) if @data_options[:section].nil?
71
+ p_exist?(@data_options[:section], *keys)
72
+ end
73
+
74
+ # remove the key under a section.
75
+ # You have to call #data_options(:section => 'MySection')
76
+ #
77
+ # * *Args* :
78
+ # - +keys+ : keys to get values from a section set by data_options.
79
+ # If section is not set, it will use :default
80
+ # * *Returns* :
81
+ # - key value.
82
+ # * *Raises* :
83
+ # Nothing
84
+ def del(*keys)
85
+ return nil if keys.length == 0
86
+ return p_del(:default, *keys) if @data_options[:section].nil?
87
+ p_del(@data_options[:section], *keys)
88
+ end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: config_layers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christophe Larsonneur
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: subhash
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.30.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.30.0
97
+ description: Manage your application configuration files easily.
98
+ email:
99
+ - clarsonneur@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .gitreview
106
+ - .rspec
107
+ - .rubocop.yml
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - config_layers.gemspec
114
+ - lib/config_layers.rb
115
+ - lib/config_layers/version.rb
116
+ - lib/prc_base_config.rb
117
+ - lib/prc_core_config.rb
118
+ - lib/prc_section_config.rb
119
+ homepage: http://github.com/forj-oss/config_layers
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.1.11
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: ConfigLayers, a simple multiple configuration management.
142
+ test_files: []
143
+ has_rdoc: