text-interpolator 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGES +4 -0
- data/lib/text_interpolator/text_interpolator.rb +21 -15
- data/lib/text_interpolator/version.rb +1 -1
- data/spec/text_interpolator_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODdkZGQ4MzYzNThlNTM4ZjRjODA2MWRmOTM1NGQzZDEwMTQ0OTgxNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjRiMTllODBjZWRlOTU4NjBjYWM2MWM5MWQ3NGVhZTJkNWQ5MjM1Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWMxYWM1ZTczN2ZkMjE0MTY4MDk4YzRjMjhmYjIxOTMwZTBjODZhNzZlNjYx
|
10
|
+
NGYwNDg2NjJmM2QwMTNlMzNjYzdiMmJmNzU4NWExZTc1NWQ4NjE3NzExYjM4
|
11
|
+
ZTRhZjhlZGE0ZjgwOTU0ZTE0ODAxNDdkMGIzOWIwMDcwNjU4OTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzRkZDA1NmYzMTc0N2U4NjgyZDVmODBiNWYzYjVjZmNkMThjYmQ1MDdjMjgz
|
14
|
+
ZDU1MDcyZmVhN2JhMWNmYzdhMWNjMjdlMTFmZjdlNzMyYjgwZDk5YWE5NzJi
|
15
|
+
ZTZkZDkxMDBjYmFlNDI5MzA3MGQ2MGM5ZjViN2FlZDczMTI5MTg=
|
data/CHANGES
CHANGED
@@ -13,9 +13,10 @@ class TextInterpolator
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def interpolate_string string, env={}
|
16
|
-
|
16
|
+
string = interpolate_env_vars string
|
17
|
+
string = string.gsub(/\#{/, '%{') if string.index(/\#\{/)
|
17
18
|
|
18
|
-
StringIO.new(
|
19
|
+
StringIO.new(string).read % env
|
19
20
|
end
|
20
21
|
|
21
22
|
def interpolate_io io, env={}
|
@@ -30,32 +31,37 @@ class TextInterpolator
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def interpolate_hash hash
|
34
|
+
hash.each do |key, value|
|
35
|
+
new_value = interpolate_env_vars value
|
36
|
+
|
37
|
+
hash[key] = new_value if new_value
|
38
|
+
end
|
39
|
+
|
33
40
|
env = hash.reduce({}) do |result, value|
|
34
41
|
result[value[0]] = value[1]
|
35
42
|
|
36
43
|
result
|
37
44
|
end
|
38
45
|
|
39
|
-
|
40
|
-
|
46
|
+
begin
|
47
|
+
substitutions = false
|
41
48
|
|
42
|
-
hash
|
43
|
-
|
49
|
+
hash.each do |key, value|
|
50
|
+
if value.index(/\#\{/)
|
51
|
+
substitutions = true
|
52
|
+
|
53
|
+
value = value.gsub(/\#{/, '%{')
|
54
|
+
|
55
|
+
hash[key] = StringIO.new(value).read % env
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end while substitutions
|
44
59
|
|
45
60
|
hash
|
46
61
|
end
|
47
62
|
|
48
63
|
private
|
49
64
|
|
50
|
-
def replace_special_symbols string
|
51
|
-
new_string = string
|
52
|
-
|
53
|
-
new_string = new_string.gsub(/\#{/, '%{') if new_string.index(/\#\{/)
|
54
|
-
new_string = interpolate_env_vars(new_string) if new_string.index('ENV[')
|
55
|
-
|
56
|
-
new_string
|
57
|
-
end
|
58
|
-
|
59
65
|
def interpolate_env_vars value
|
60
66
|
while value.index('ENV[')
|
61
67
|
value = interpolate_env_var value
|
@@ -60,7 +60,7 @@ describe TextInterpolator do
|
|
60
60
|
'"oracle_base": "/usr/local/oracle",' +
|
61
61
|
'"oracle_version": "11.2.0.4.0",'+
|
62
62
|
|
63
|
-
'"src_dir": "downloads",' +
|
63
|
+
'"src_dir": "#{user}/downloads",' +
|
64
64
|
'"dest_dir": "#{oracle_base}/instantclient_11_2",' +
|
65
65
|
|
66
66
|
'"basic_zip": "#{src_dir}/instantclient-basic-macos.x64-#{oracle_version}.zip"' +
|
@@ -73,7 +73,7 @@ describe TextInterpolator do
|
|
73
73
|
expect(result[:user]).to eq ENV['USER']
|
74
74
|
expect(result[:oracle_base]).to eq '/usr/local/oracle'
|
75
75
|
expect(result[:dest_dir]).to eq '/usr/local/oracle/instantclient_11_2'
|
76
|
-
expect(result[:basic_zip]).to eq 'downloads/instantclient-basic-macos.x64-11.2.0.4.0.zip'
|
76
|
+
expect(result[:basic_zip]).to eq ENV['USER'] + '/downloads/instantclient-basic-macos.x64-11.2.0.4.0.zip'
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|