dry-config 1.1.3 → 1.1.4
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 +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +16 -0
- data/dry-config.gemspec +2 -2
- data/lib/dry/config/base.rb +31 -2
- data/lib/dry/config/version.rb +1 -1
- data/spec/dry/config/docker-compose-template-simple.yml +22 -0
- data/spec/dry/config/docker-compose-template.yml +27 -0
- data/spec/dry/config/interpolation_spec.rb +92 -0
- data/spec/spec_helper.rb +3 -0
- metadata +17 -10
- data/.rvmrc +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e5ef4a6ae7ca95ba67b4727fe8137765874464f
|
4
|
+
data.tar.gz: 90bf572de240fd4250dd88353fed2be01b4b6bde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db019775409ec7a2f0aa72a47f903c8dbe25d40a4f77b6af9af3b466c701ba73c2bb642c1eabfe96a9daf8be55061a7d4298eac7998de1c96591ae0d5570cbca
|
7
|
+
data.tar.gz: 44db43c679ec43e5187f773fe90cbad3e76baeb0c4809d9737268894125bd1255fe284fd41ecf09d0ce3dcd105a6e10adef7cb822b6de728381fe35c7d4167ea
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--require spec_helper
|
2
|
+
--require spec_helper
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
dry_config
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.2
|
data/README.md
CHANGED
@@ -111,6 +111,22 @@ config.options[:'aws:autoscaling:launchconfiguration'][:InstanceType] # t1.large
|
|
111
111
|
- An optional `#seed_default_configuration` allows you to provide a configuration base
|
112
112
|
- `#clear` will restore to the seed configuration, allowing you to `#load!` new settings.
|
113
113
|
|
114
|
+
## ENV Interpolation/substitution/expansion
|
115
|
+
|
116
|
+
ENV variable substitution is supported and enabled by default. It may be disabled by initializing with `{interpolation: false}`.
|
117
|
+
|
118
|
+
The following formats are acceptable:
|
119
|
+
|
120
|
+
```yaml
|
121
|
+
interpolations:
|
122
|
+
- ~/foo
|
123
|
+
- $HOME/foo
|
124
|
+
- ${HOME}/foo
|
125
|
+
- #{HOME}/foo
|
126
|
+
# mixed example
|
127
|
+
- ~/docker/mysql/${PROJECT_NAME}-${BUILD}:/var/lib/mysql:rw
|
128
|
+
```
|
129
|
+
|
114
130
|
## White Label sample
|
115
131
|
|
116
132
|
```ruby
|
data/dry-config.gemspec
CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
s.add_development_dependency 'bundler'
|
21
|
+
s.add_development_dependency 'bundler'
|
22
22
|
s.add_development_dependency 'rake'
|
23
|
-
s.add_development_dependency 'rspec'
|
23
|
+
s.add_development_dependency 'rspec'
|
24
24
|
|
25
25
|
end
|
data/lib/dry/config/base.rb
CHANGED
@@ -17,7 +17,9 @@ module Dry
|
|
17
17
|
attr_reader :environment
|
18
18
|
attr_reader :filenames
|
19
19
|
|
20
|
-
def initialize(
|
20
|
+
def initialize(options = {})
|
21
|
+
@options = {interpolation: true}.merge options
|
22
|
+
|
21
23
|
seed_default_configuration
|
22
24
|
|
23
25
|
# used for pruning initial base set. See #load!
|
@@ -80,11 +82,38 @@ module Dry
|
|
80
82
|
end
|
81
83
|
|
82
84
|
def load_yaml_file(filename)
|
83
|
-
|
85
|
+
|
86
|
+
# without interpolation
|
87
|
+
# config = Psych.load_file(filename)
|
88
|
+
|
89
|
+
# get file contents as string
|
90
|
+
file = File.open(filename, 'r:bom|utf-8')
|
91
|
+
contents = file.read
|
92
|
+
|
93
|
+
if @options[:interpolation]
|
94
|
+
# interpolate/substitute/expand ENV variables with the string contents before parsing
|
95
|
+
# bash - $VAR
|
96
|
+
contents = contents.gsub(/\$(\w+)/) { ENV[$1] }
|
97
|
+
# bash - ${VAR}
|
98
|
+
contents = contents.gsub(/\${(\w+)}/) { ENV[$1] }
|
99
|
+
# bash - ~ is ENV['HOME']
|
100
|
+
contents = contents.gsub(/(~)/) { ENV['HOME'] }
|
101
|
+
# ruby - #{VAR}
|
102
|
+
contents = contents.gsub(/\#{(\w+)}/) { ENV[$1] }
|
103
|
+
end
|
104
|
+
# now parse
|
105
|
+
config = Psych.load(contents, filename)
|
106
|
+
|
84
107
|
raise "Failed to load #{filename}" if config.nil?
|
85
108
|
config.deep_symbolize
|
86
109
|
end
|
87
110
|
|
111
|
+
def write_yaml_file(filename)
|
112
|
+
File.open(filename, 'w') do |file|
|
113
|
+
file.write(Psych.dump(@configuration))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
88
117
|
def reload!
|
89
118
|
clear
|
90
119
|
load! @environment, @filenames
|
data/lib/dry/config/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# https://docs.docker.com/v1.6/compose/cli/#environment-variables
|
2
|
+
web:
|
3
|
+
build: .
|
4
|
+
command: bin/rails server --port 3000 --binding 0.0.0.0
|
5
|
+
ports:
|
6
|
+
- "3000:3000"
|
7
|
+
links:
|
8
|
+
- db
|
9
|
+
volumes:
|
10
|
+
- .:/myapp
|
11
|
+
db:
|
12
|
+
# https://github.com/docker-library/docs/tree/master/mysql
|
13
|
+
image: library/mysql:5.7.6
|
14
|
+
ports:
|
15
|
+
- "3306:3306"
|
16
|
+
# volumes:
|
17
|
+
# - ~/docker/mysql/${PROJECT_NAME}:/var/lib/mysql:rw
|
18
|
+
# interpolation coming in compose 1.5
|
19
|
+
# https://github.com/docker/compose/pull/1765
|
20
|
+
# https://github.com/docker/compose/issues/1377
|
21
|
+
environment:
|
22
|
+
- MYSQL_ALLOW_EMPTY_PASSWORD=true
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# https://docs.docker.com/v1.6/compose/cli/#environment-variables
|
2
|
+
web:
|
3
|
+
build: .
|
4
|
+
command: bin/rails server --port 3000 --binding 0.0.0.0
|
5
|
+
ports:
|
6
|
+
- "3000:3000"
|
7
|
+
links:
|
8
|
+
- db
|
9
|
+
volumes:
|
10
|
+
- .:/myapp
|
11
|
+
db:
|
12
|
+
# https://github.com/docker-library/docs/tree/master/mysql
|
13
|
+
image: library/mysql:5.7.6
|
14
|
+
ports:
|
15
|
+
- "3306:3306"
|
16
|
+
volumes:
|
17
|
+
- ~/docker/mysql/${PROJECT_NAME}-${BUILD}:/var/lib/mysql:rw
|
18
|
+
# interpolation coming in compose 1.5
|
19
|
+
# https://github.com/docker/compose/pull/1765
|
20
|
+
# https://github.com/docker/compose/issues/1377
|
21
|
+
environment:
|
22
|
+
- MYSQL_ALLOW_EMPTY_PASSWORD=true
|
23
|
+
interpolations:
|
24
|
+
- ~/foo
|
25
|
+
- $HOME/foo
|
26
|
+
- ${HOME}/foo
|
27
|
+
- #{HOME}/foo
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
describe Dry::Config::Base do
|
5
|
+
|
6
|
+
class ComposeConfig < Dry::Config::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
subject(:new_compose) { ComposeConfig.new }
|
10
|
+
|
11
|
+
context 'no interpolation' do
|
12
|
+
let(:config_file_name) { 'docker-compose-template-simple.yml' }
|
13
|
+
subject(:compose) { new_compose}
|
14
|
+
before(:each) { FileUtils.rm_r tmp_dir }
|
15
|
+
|
16
|
+
it 'should read file and write file with all values intact' do
|
17
|
+
compose.clear
|
18
|
+
compose.load!(nil, config_file_name_path)
|
19
|
+
|
20
|
+
expected_config = compose.configuration
|
21
|
+
tmp_file = tmp_file(config_file_name.gsub('.', '-out.'))
|
22
|
+
compose.write_yaml_file(tmp_file)
|
23
|
+
|
24
|
+
compose.clear
|
25
|
+
compose.load!(nil, tmp_file)
|
26
|
+
actual_config = compose.configuration
|
27
|
+
|
28
|
+
expect(actual_config).to eq expected_config
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'interpolation' do
|
33
|
+
let(:config_file_name) { 'docker-compose-template.yml' }
|
34
|
+
before(:each) {
|
35
|
+
ENV['HOME'] = '/Users/rosskevin'
|
36
|
+
ENV['PROJECT_NAME'] = 'acme'
|
37
|
+
ENV['BUILD'] = '888'
|
38
|
+
}
|
39
|
+
subject(:compose) {
|
40
|
+
compose = new_compose
|
41
|
+
compose.clear
|
42
|
+
compose.load!(nil, config_file_name_path)
|
43
|
+
compose
|
44
|
+
}
|
45
|
+
let(:configuration) { compose.configuration }
|
46
|
+
|
47
|
+
it 'parses structure' do
|
48
|
+
expect(configuration[:db]).not_to be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'multiple' do
|
52
|
+
expect(configuration[:db][:volumes][0]).to eq '/Users/rosskevin/docker/mysql/acme-888:/var/lib/mysql:rw'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'all varieties' do
|
56
|
+
interpolations = configuration[:interpolations]
|
57
|
+
interpolations.each do |result|
|
58
|
+
expect(result).to eq '/Users/rosskevin/foo'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'disabled' do
|
63
|
+
subject(:new_compose) {ComposeConfig.new(interpolation: false)}
|
64
|
+
|
65
|
+
it 'parses structure' do
|
66
|
+
expect(configuration[:db]).not_to be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'it does not interpolate' do
|
70
|
+
expect(configuration[:db][:volumes][0]).to eq '~/docker/mysql/${PROJECT_NAME}-${BUILD}:/var/lib/mysql:rw'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def config_file_name_path
|
79
|
+
File.expand_path("../#{config_file_name}", __FILE__)
|
80
|
+
end
|
81
|
+
|
82
|
+
def tmp_file(filename)
|
83
|
+
file = File.expand_path(filename, tmp_dir)
|
84
|
+
file
|
85
|
+
end
|
86
|
+
|
87
|
+
def tmp_dir
|
88
|
+
dir = File.expand_path("../.././../../tmp/interpolation", __FILE__)
|
89
|
+
FileUtils.mkdir_p(dir) unless File.exists? dir
|
90
|
+
dir
|
91
|
+
end
|
92
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
description: Simple base class for DRY environment based configurations.
|
56
56
|
email:
|
57
57
|
- kevin.ross@alienfast.com
|
@@ -61,7 +61,8 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
-
- ".
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -74,6 +75,9 @@ files:
|
|
74
75
|
- spec/dry/config/acme.yml
|
75
76
|
- spec/dry/config/base_spec.rb
|
76
77
|
- spec/dry/config/deep_symbolizable_spec.rb
|
78
|
+
- spec/dry/config/docker-compose-template-simple.yml
|
79
|
+
- spec/dry/config/docker-compose-template.yml
|
80
|
+
- spec/dry/config/interpolation_spec.rb
|
77
81
|
- spec/dry/config/white-label/acme.com.yml
|
78
82
|
- spec/dry/config/white-label/base.yml
|
79
83
|
- spec/dry/config/white-label/scheduling.acme.com.yml
|
@@ -98,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
102
|
version: '0'
|
99
103
|
requirements: []
|
100
104
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.4.8
|
102
106
|
signing_key:
|
103
107
|
specification_version: 4
|
104
108
|
summary: Simple base class for DRY environment based configurations.
|
@@ -106,6 +110,9 @@ test_files:
|
|
106
110
|
- spec/dry/config/acme.yml
|
107
111
|
- spec/dry/config/base_spec.rb
|
108
112
|
- spec/dry/config/deep_symbolizable_spec.rb
|
113
|
+
- spec/dry/config/docker-compose-template-simple.yml
|
114
|
+
- spec/dry/config/docker-compose-template.yml
|
115
|
+
- spec/dry/config/interpolation_spec.rb
|
109
116
|
- spec/dry/config/white-label/acme.com.yml
|
110
117
|
- spec/dry/config/white-label/base.yml
|
111
118
|
- spec/dry/config/white-label/scheduling.acme.com.yml
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use ruby-2.1.2@dry_config --create
|