config-parser 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fc6869f1aa46b1446eff6a47d6dda33e72a7a50d
4
- data.tar.gz: ac300beccf597924911ac279b2c117112cd895d8
2
+ SHA256:
3
+ metadata.gz: 87a783bc84cb4b18d7c595ab1d189fc96de95b37be769e8d9283b6a6f7de6dd3
4
+ data.tar.gz: ea1ea23ec0ac507e57148e407ced402f96a26da73baf18ba352794eafe74e978
5
5
  SHA512:
6
- metadata.gz: 01a2a7aec84c8d24ab2d58c90238ea463a5014e1403f880b06aa8c81274a915b3b60c63314c02e90406bcdbd980c7fe689e71dd51702bae8d292e55a440fbe08
7
- data.tar.gz: f81280199802c941c3b7a0ef3fc0097b8840a275be38990d392388a9ae6ab5ef2e84807ed103c1180b1ec895a5cf9f51193abc061e6c6e119ee90cdea0156dd7
6
+ metadata.gz: 0fdea9dede402cd33725eee39f9261eadd47890e0cc5d58b06be7bf3313fe2a7d91fb7676636c86627b30158f13feb5759e6edd0e31f6757ac8848a72001fced
7
+ data.tar.gz: f26277e7c6874c3bf4ad4cd33f7c80859ae80028f9a5145a2661b6aa8c0b5e7cbeb202853548d22e29c71270cbd1ca7c07a24c38531860a101f7bac00c801bc3
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ before_install:
5
+ - gem install bundler -v '< 2' --conservative
6
+
7
+ rvm:
8
+ - 1.9
9
+ - 2.0
10
+ - 2.3.3
11
+ - 2.5.1
12
+
13
+ sudo: false
14
+
15
+ script:
16
+ - 'COVERAGE=true bundle exec rspec'
data/Gemfile.lock CHANGED
@@ -1,36 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- config-parser (0.3.0)
4
+ config-parser (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ deep_merge (1.2.1)
9
10
  diff-lcs (1.3)
10
- rspec (3.5.0)
11
- rspec-core (~> 3.5.0)
12
- rspec-expectations (~> 3.5.0)
13
- rspec-mocks (~> 3.5.0)
14
- rspec-core (3.5.4)
15
- rspec-support (~> 3.5.0)
16
- rspec-expectations (3.5.0)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.0)
16
+ rspec-support (~> 3.9.0)
17
+ rspec-expectations (3.9.0)
17
18
  diff-lcs (>= 1.2.0, < 2.0)
18
- rspec-support (~> 3.5.0)
19
+ rspec-support (~> 3.9.0)
19
20
  rspec-its (1.2.0)
20
21
  rspec-core (>= 3.0.0)
21
22
  rspec-expectations (>= 3.0.0)
22
- rspec-mocks (3.5.0)
23
+ rspec-mocks (3.9.0)
23
24
  diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.5.0)
25
- rspec-support (3.5.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-support (3.9.0)
26
27
 
27
28
  PLATFORMS
28
29
  ruby
29
30
 
30
31
  DEPENDENCIES
31
32
  config-parser!
33
+ deep_merge
32
34
  rspec
33
35
  rspec-its
34
36
 
35
37
  BUNDLED WITH
36
- 1.14.6
38
+ 1.16.2
@@ -1,22 +1,24 @@
1
- ## Config parser gem
1
+ [![Build Status](https://travis-ci.org/openSUSE/rubygem_config-parser.png?branch=master)](https://travis-ci.org/openSUSE/rubygem_config-parser)
2
2
 
3
- Parsing an options.yml file into a Hash with convenience methods like
3
+ ## Ruby Config Parser
4
+
5
+ Providing config values for your Ruby app with convenience methods like
4
6
  overwriting variables per Rails environment and overwriting variables with a local
5
7
  options_local.yml file.
6
8
 
7
9
  ### Installation
8
10
 
9
- The best way to install is with RubyGems:
11
+ The best way to install is with [RubyGems](https://rubygems.org/gems/config-parser):
10
12
 
11
- $ [sudo] gem install config-parser
13
+ $ gem install config-parser
12
14
 
13
- Or better still, just add it to your Gemfile:
15
+ Or better still, just add it to your `Gemfile`:
14
16
 
15
17
  gem 'config-parser'
16
18
 
17
19
  ### Defaults
18
20
 
19
- Per default the parser will search for the config file at config/options.yml and config/options-local.yml.
21
+ Per default the parser will search for the config file at `config/options.yml` and local overrides at `config/options-local.yml`.
20
22
 
21
23
 
22
24
  ### Example
@@ -33,7 +35,12 @@ Example config file:
33
35
  When running in the production environment, the mailer_delivery_method will be set to
34
36
  'smtp'. The same works for all other environments. The optional options_local.yml file
35
37
  would have the same layout.
36
- When used from a Rails app, just include in your application.rb:
38
+
39
+ The precedence of config values goes like this (from lowest to highest):
40
+
41
+ `options.yml default section -> options.yml environment section -> options-local.yml default section -> options-local.yml environment section`
42
+
43
+ When used from a Rails app, just include in your `application.rb`:
37
44
 
38
45
  ```ruby
39
46
  OPTS = Common::Options.new
@@ -43,6 +50,7 @@ and you can use the config variables like:
43
50
 
44
51
  ```ruby
45
52
  OPTS.<variable_name>
53
+ OPTS.<variable_name>[:nested_value]
46
54
  ```
47
55
 
48
56
  Also, you can pass main config and local config location as well as environment to load
@@ -1,18 +1,17 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "config-parser"
3
3
  gem.summary = %Q{Parsing an options.yml file into a Hash with convenience.}
4
- gem.description = "Parsing an options.yml file into a Hash with convenience methods like
5
- overwriting variables per Rails environment and overwriting variables with a local
6
- options_local.yml file."
4
+ gem.description = "Providing config values for your Ruby app with convenience methods like
5
+ overwriting variables per Rails environment and overwriting variables with a local
6
+ options_local.yml file."
7
7
  gem.homepage = "https://github.com/openSUSE/rubygem_config-parser"
8
8
  gem.authors = ['cschum@suse.de', 'tom@opensuse.org', 'kpimenov@suse.de']
9
9
  gem.files = `git ls-files`.split("\n")
10
10
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
11
11
  gem.require_paths = ['lib']
12
- gem.version = '0.3.0'
12
+ gem.version = '0.4.0'
13
13
  gem.license = 'MIT'
14
14
  gem.add_development_dependency 'rspec'
15
15
  gem.add_development_dependency 'rspec-its'
16
+ gem.add_development_dependency 'deep_merge'
16
17
  end
17
-
18
-
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'yaml'
24
24
  require 'erb'
25
+ require 'deep_merge'
25
26
 
26
27
  require "#{File.dirname(__FILE__)}/utils"
27
28
 
@@ -111,14 +112,14 @@ module Common
111
112
  elsif @persistent_local_cfg_file && File.exists?(@persistent_local_cfg_file)
112
113
  vputs "Loading '#{@persistent_local_cfg_file}'", args[:verbose]
113
114
  update_options(@persistent_local_cfg_file, options)
114
- elsif File.exists? @local_cfg_file
115
+ elsif @local_cfg_file && File.exists?(@local_cfg_file)
115
116
  vputs "Loading '#{@local_cfg_file}'", args[:verbose]
116
117
  update_options(@local_cfg_file, options)
117
118
  end
118
119
 
119
120
  if args[:environment]
120
121
  vputs "Using environment '#{args[:environment]}'", args[:verbose]
121
- options = (options['default']||{}).update(options[args[:environment]]||{})
122
+ options = (options['default']||{}).deep_merge!(options[args[:environment]]||{})
122
123
  end
123
124
 
124
125
  options.update(update_options)
@@ -164,16 +165,10 @@ module Common
164
165
  raise NoMethodError.new("undefined method `#{key}' for Options:Class", "unknown_key")
165
166
  end
166
167
 
167
- # Update options.
168
+ # Merge options with content of <file>.
168
169
  def update_options file, options
169
- load_file(file).each do |k, v|
170
- next unless v
171
- if options[k]
172
- options[k].update(v)
173
- else
174
- options[k] = v
175
- end
176
- end
170
+ options.deep_merge!(load_file(file))
177
171
  end
172
+
178
173
  end
179
174
  end
@@ -2,3 +2,21 @@ default:
2
2
  plain_key: plain_value
3
3
  erb_key: <%= %w(erb value).join('_') %>
4
4
  mixed_key: "<%= 'mixed_' %>value"
5
+
6
+ nested:
7
+ nested_key: nested_value_default
8
+ nested_key2: nested_value_default2
9
+
10
+ nested_env:
11
+ nested_key: nested_value_env
12
+ nested_key2: nested_value_env2
13
+
14
+ env_overwrite_key: env_value
15
+
16
+
17
+ test:
18
+ env_only_key: test_value
19
+ env_overwrite_key: test_value
20
+
21
+ nested_env:
22
+ nested_key: nested_value_test
@@ -0,0 +1,14 @@
1
+ default:
2
+
3
+ plain_key: plain_value_local
4
+
5
+ nested:
6
+ nested_key: nested_value_local
7
+
8
+
9
+ test:
10
+ env_only_key: test_value_local
11
+ env_overwrite_key: test_value_local
12
+
13
+ nested_env:
14
+ nested_key: nested_value_test_local
@@ -0,0 +1,26 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Common::Options do
4
+ subject { Common::Options.new('spec/fixtures/example_config.yml', 'spec/fixtures/example_config_local.yml', 'test') }
5
+
6
+ it 'reads default value' do
7
+ expect( subject.mixed_key ).to eq("mixed_value")
8
+ end
9
+
10
+ it 'reads local value' do
11
+ expect( subject.plain_key ).to eq("plain_value_local")
12
+ end
13
+
14
+ it 'reads local nested value' do
15
+ expect( subject.nested['nested_key'] ).to eq("nested_value_local")
16
+ end
17
+
18
+ it 'reads nested value for local env' do
19
+ expect( subject.nested_env['nested_key']).to eq("nested_value_test_local")
20
+ end
21
+
22
+ it 'keeps default for not overwritten parts of nested set' do
23
+ expect(subject.nested_env['nested_key2']).to eq("nested_value_env2")
24
+ end
25
+
26
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Common::Options do
4
+ subject { Common::Options.new('spec/fixtures/example_config.yml', nil, 'test') }
5
+
6
+ it 'reads nested value' do
7
+ expect( subject.nested['nested_key']).to eq("nested_value_default")
8
+ end
9
+
10
+ it 'reads nested value for env' do
11
+ expect( subject.nested_env['nested_key']).to eq("nested_value_test")
12
+ end
13
+
14
+ it 'keeps default for not overwritten parts of nested set' do
15
+ expect(subject.nested_env['nested_key2']).to eq("nested_value_env2")
16
+ end
17
+
18
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Common::Options do
4
+ subject { Common::Options.new('spec/fixtures/example_config.yml') }
5
+
6
+ it 'reads value' do
7
+ expect( subject.plain_key ).to eq("plain_value")
8
+ end
9
+
10
+ it 'reads nested value' do
11
+ expect( subject.nested['nested_key'] ).to eq("nested_value_default")
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cschum@suse.de
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-04-05 00:00:00.000000000 Z
13
+ date: 2019-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -40,26 +40,45 @@ dependencies:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: deep_merge
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
43
57
  description: |-
44
- Parsing an options.yml file into a Hash with convenience methods like
45
- overwriting variables per Rails environment and overwriting variables with a local
46
- options_local.yml file.
58
+ Providing config values for your Ruby app with convenience methods like
59
+ overwriting variables per Rails environment and overwriting variables with a local
60
+ options_local.yml file.
47
61
  email:
48
62
  executables: []
49
63
  extensions: []
50
64
  extra_rdoc_files: []
51
65
  files:
52
66
  - ".gitignore"
67
+ - ".travis.yml"
53
68
  - Gemfile
54
69
  - Gemfile.lock
55
70
  - LICENSE
56
- - README.markdown
71
+ - README.md
57
72
  - config-parser.gemspec
58
73
  - lib/common/options.rb
59
74
  - lib/common/utils.rb
60
75
  - lib/config-parser.rb
61
76
  - spec/erb_interpolation_spec.rb
62
77
  - spec/fixtures/example_config.yml
78
+ - spec/fixtures/example_config_local.yml
79
+ - spec/local_overwrite_spec.rb
80
+ - spec/nested_values_spec.rb
81
+ - spec/read_values_spec.rb
63
82
  - spec/spec_helper.rb
64
83
  homepage: https://github.com/openSUSE/rubygem_config-parser
65
84
  licenses:
@@ -81,11 +100,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
100
  version: '0'
82
101
  requirements: []
83
102
  rubyforge_project:
84
- rubygems_version: 2.6.8
103
+ rubygems_version: 2.7.6
85
104
  signing_key:
86
105
  specification_version: 4
87
106
  summary: Parsing an options.yml file into a Hash with convenience.
88
107
  test_files:
89
108
  - spec/erb_interpolation_spec.rb
90
109
  - spec/fixtures/example_config.yml
110
+ - spec/fixtures/example_config_local.yml
111
+ - spec/local_overwrite_spec.rb
112
+ - spec/nested_values_spec.rb
113
+ - spec/read_values_spec.rb
91
114
  - spec/spec_helper.rb