rakeoe 0.0.12 → 0.0.13
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/lib/rakeoe/key_value_reader.rb +28 -7
- data/lib/rakeoe/version.rb +1 -1
- data/spec/key_value_reader_spec.rb +103 -0
- data/spec/rakoe_spec.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebbfc30b0c0cb5a43e8dfd56ffdde975cf61fa12
|
4
|
+
data.tar.gz: 23be7f3515f77a4f1f77cea6d975c0e7129fb73d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be508bbd285bbc74175493c126bafbb9fb9b9900c10de5c4bbfaa074fb740aeac39fc12b88d466013d5b240a78257344d41ddf9a1a25b3ebdc3a00d12560fa2
|
7
|
+
data.tar.gz: 35bc22f0c92d6b71569217bbc835a21c4583f4e20dddf58683c32a57f8d53d1f1459a5c74ae44ceeecdced1805b70bea58a1545b9bf2f2eba75140f43d7dadaa
|
@@ -18,25 +18,46 @@ module RakeOE
|
|
18
18
|
class KeyValueReader
|
19
19
|
attr_accessor :env
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
# Constructor
|
22
|
+
# @param [String, Hash] par If given as string, it should be a file name to the key-value file
|
23
|
+
# if given as Hash, it already contains a key-value mapping that should be $-substituted
|
24
|
+
def initialize(par)
|
25
|
+
if par.is_a? String
|
26
|
+
raise "No such file #{par}" unless File.exist?(par)
|
27
|
+
@file_name = par
|
28
|
+
@env = self.class.read_file(@file_name)
|
29
|
+
elsif par.is_a? Hash
|
30
|
+
@env = par
|
31
|
+
end
|
23
32
|
|
24
|
-
@file_name = env_file
|
25
|
-
@env = self.class.read_file(@file_name)
|
26
33
|
self.class.substitute_dollar_symbols!(@env)
|
27
34
|
end
|
28
35
|
|
29
36
|
# Substitute all dollar values with either already parsed
|
30
37
|
# values or with system environment variables
|
38
|
+
# @param [Hash] env Hash containing values that have to be expanded
|
39
|
+
#
|
31
40
|
def self.substitute_dollar_symbols!(env)
|
32
|
-
|
41
|
+
more_dollars = false
|
33
42
|
resolved_dollar_vars = env.each_with_object(Hash.new) do |var, obj|
|
34
|
-
# expand all
|
43
|
+
# expand all variable patterns and try to match ENV or env
|
35
44
|
pattern = /\$([a-zA-Z_]+[a-zA-Z0-9_]*)|\$\{(.+)\}/
|
36
|
-
obj[var[0]] = var[1].gsub(pattern)
|
45
|
+
obj[var[0]] = var[1].gsub(pattern) do
|
46
|
+
# if in ENV, use it
|
47
|
+
rv = ENV[$1||$2]
|
48
|
+
unless rv
|
49
|
+
# if not in ENV, use env, but only if not same as string we want to substitute
|
50
|
+
rv = env[$1||$2] if env[$1||$2] != var[1]
|
51
|
+
end
|
52
|
+
rv
|
53
|
+
end
|
54
|
+
# if still contains dollar symbol: recurse at end
|
55
|
+
more_dollars = true if obj[var[0]] =~ pattern
|
37
56
|
end
|
38
57
|
# overwrite old values with resolved values
|
39
58
|
env.merge!(resolved_dollar_vars)
|
59
|
+
|
60
|
+
self.substitute_dollar_symbols!(env) if more_dollars
|
40
61
|
end
|
41
62
|
|
42
63
|
|
data/lib/rakeoe/version.rb
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Expanded Key-Values' do
|
4
|
+
|
5
|
+
it 'should replace one variable' do
|
6
|
+
h = {
|
7
|
+
'VAL1' => 'BLA',
|
8
|
+
'VAL2' => 'BLA $VAL1'
|
9
|
+
}
|
10
|
+
kvr = KeyValueReader.new(h)
|
11
|
+
expect(kvr).not_to be_nil
|
12
|
+
expect(kvr.env['VAL2']).to eq('BLA BLA')
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
it 'should replace not existing variable with nothing' do
|
17
|
+
h = {
|
18
|
+
'VAL1' => '$VAL2'
|
19
|
+
}
|
20
|
+
kvr = KeyValueReader.new(h)
|
21
|
+
expect(kvr).not_to be_nil
|
22
|
+
expect(kvr.env['VAL1']).to eq('')
|
23
|
+
expect(kvr.env['VAL1'].size).to be == 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should replace later introduced variable' do
|
27
|
+
h = {
|
28
|
+
'VAL1' => '$VAL2',
|
29
|
+
'VAL2' => 'BLA'
|
30
|
+
}
|
31
|
+
kvr = KeyValueReader.new(h)
|
32
|
+
expect(kvr).not_to be_nil
|
33
|
+
expect(kvr.env['VAL1']).to eq('BLA')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should expand single PATH variable' do
|
37
|
+
h = {
|
38
|
+
'VAL1' => '$PATH',
|
39
|
+
}
|
40
|
+
kvr = KeyValueReader.new(h)
|
41
|
+
expect(kvr).not_to be_nil
|
42
|
+
expect(kvr.env['VAL1']).not_to be_nil
|
43
|
+
expect(kvr.env['VAL1']).to eq(ENV['PATH'])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should expand PATH variable with text' do
|
47
|
+
h = {
|
48
|
+
'VAL1' => '/path/to/somewhere:$PATH',
|
49
|
+
}
|
50
|
+
kvr = KeyValueReader.new(h)
|
51
|
+
expect(kvr).not_to be_nil
|
52
|
+
expect(kvr.env['VAL1']).to eq('/path/to/somewhere:' + ENV['PATH'])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should expand variable to final reference' do
|
56
|
+
h = {
|
57
|
+
'VAL0' => 'BLA',
|
58
|
+
'VAL1' => '$VAL0',
|
59
|
+
'VAL2' => '$VAL1',
|
60
|
+
'VAL3' => '$VAL2',
|
61
|
+
}
|
62
|
+
kvr = KeyValueReader.new(h)
|
63
|
+
expect(kvr).not_to be_nil
|
64
|
+
expect(kvr.env['VAL3']).to eq('BLA')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should expand variable to final reference even if only forward references are used' do
|
68
|
+
h = {
|
69
|
+
'VAL3' => '$VAL2',
|
70
|
+
'VAL2' => '$VAL1',
|
71
|
+
'VAL1' => '$VAL0',
|
72
|
+
'VAL0' => 'BLA',
|
73
|
+
}
|
74
|
+
kvr = KeyValueReader.new(h)
|
75
|
+
expect(kvr).not_to be_nil
|
76
|
+
expect(kvr.env['VAL3']).to eq('BLA')
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should expand variable to empty if no final reference' do
|
80
|
+
h = {
|
81
|
+
'VAL0' => '$BOGUS',
|
82
|
+
'VAL1' => '$VAL0',
|
83
|
+
'VAL2' => '$VAL1',
|
84
|
+
'VAL3' => '$VAL2',
|
85
|
+
}
|
86
|
+
kvr = KeyValueReader.new(h)
|
87
|
+
expect(kvr).not_to be_nil
|
88
|
+
expect(kvr.env['VAL3']).to eq('')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should expand multiple variables in one definition' do
|
92
|
+
h = {
|
93
|
+
'VAL0' => 'NICE',
|
94
|
+
'VAL1' => '$VAL0',
|
95
|
+
'VAL2' => '$VAL1',
|
96
|
+
'VAL3' => '$VAL2 $VAL1 $VAL0',
|
97
|
+
}
|
98
|
+
kvr = KeyValueReader.new(h)
|
99
|
+
expect(kvr).not_to be_nil
|
100
|
+
expect(kvr.env['VAL3']).to eq('NICE NICE NICE')
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/spec/rakoe_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rakeoe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schnell
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/rakeoe/toolchain/environment-arm-stm32f072-eabi.osx
|
88
88
|
- lib/rakeoe/version.rb
|
89
89
|
- rakeoe.gemspec
|
90
|
+
- spec/key_value_reader_spec.rb
|
90
91
|
- spec/rakoe_spec.rb
|
91
92
|
- spec/spec_helper.rb
|
92
93
|
- templates/platform/environment-arm-stm32f0-eabi
|
@@ -119,5 +120,6 @@ specification_version: 4
|
|
119
120
|
summary: 'Rake Optimized for Embedded: build system for test driven Embedded C/C++
|
120
121
|
Development based on Ruby Rake.'
|
121
122
|
test_files:
|
123
|
+
- spec/key_value_reader_spec.rb
|
122
124
|
- spec/rakoe_spec.rb
|
123
125
|
- spec/spec_helper.rb
|