text-interpolator 1.0.2 → 1.0.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDk5ZDBkYjAxZTRmNjAzNmY5NjgxNDI0Njc4Y2FhYjM0YTJkZDIzNA==
4
+ ODdkZGQ4MzYzNThlNTM4ZjRjODA2MWRmOTM1NGQzZDEwMTQ0OTgxNg==
5
5
  data.tar.gz: !binary |-
6
- NGZiNWZiNTExMjBjNWVhMGU3NTczNjYzZGMzZjk2YzgxMWQyMzMwYQ==
6
+ NjRiMTllODBjZWRlOTU4NjBjYWM2MWM5MWQ3NGVhZTJkNWQ5MjM1Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTkyYmY5NmM0NmQ2NTQ3NDU5ZTRkZDFkOTM1ODg2MDA4MTIxNmJhNjM4NWEx
10
- Njg5NWM1OWY4OTI0MzE1YTcwMTE2ZWQwMzc4NzUyOTBmNGUzZThkMjMxZjQ3
11
- NzM2MGRkOTQ3YzI5YmY0NDZjNWNkYzBlZDFkODMyOGE1MDc0NzE=
9
+ OWMxYWM1ZTczN2ZkMjE0MTY4MDk4YzRjMjhmYjIxOTMwZTBjODZhNzZlNjYx
10
+ NGYwNDg2NjJmM2QwMTNlMzNjYzdiMmJmNzU4NWExZTc1NWQ4NjE3NzExYjM4
11
+ ZTRhZjhlZGE0ZjgwOTU0ZTE0ODAxNDdkMGIzOWIwMDcwNjU4OTE=
12
12
  data.tar.gz: !binary |-
13
- ZmZkNGE5ZGU4Yjg4OWEwZmZlNTYwODg2MDUzMjQ1MzVkNGUwZDFjNTYzYWJj
14
- N2Q5MGMyYWU5ZTU0YmQ5OWRhMzExODJkYjIwMzVhMjRhMGE3MDE0Y2Q2N2Yy
15
- MWFkNzU3YWNiZmQ3ZmRlMjQwZWM5ZjAxNmJjZDFkN2RmY2Q3NzQ=
13
+ NzRkZDA1NmYzMTc0N2U4NjgyZDVmODBiNWYzYjVjZmNkMThjYmQ1MDdjMjgz
14
+ ZDU1MDcyZmVhN2JhMWNmYzdhMWNjMjdlMTFmZjdlNzMyYjgwZDk5YWE5NzJi
15
+ ZTZkZDkxMDBjYmFlNDI5MzA3MGQ2MGM5ZjViN2FlZDczMTI5MTg=
data/CHANGES CHANGED
@@ -10,4 +10,8 @@
10
10
 
11
11
  == Version 1.0.2
12
12
 
13
+ * Bug fix.
14
+
15
+ == Version 1.0.3
16
+
13
17
  * Bug fix.
@@ -13,9 +13,10 @@ class TextInterpolator
13
13
  end
14
14
 
15
15
  def interpolate_string string, env={}
16
- new_string = replace_special_symbols(string)
16
+ string = interpolate_env_vars string
17
+ string = string.gsub(/\#{/, '%{') if string.index(/\#\{/)
17
18
 
18
- StringIO.new(new_string).read % env
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
- hash.each do |key, value|
40
- new_value = replace_special_symbols(value)
46
+ begin
47
+ substitutions = false
41
48
 
42
- hash[key] = StringIO.new(new_value).read % env
43
- end
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
@@ -1,3 +1,3 @@
1
1
  class TextInterpolator
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text-interpolator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets