text-interpolator 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGIxNTMzNDU2ODc3YmM2NDAzMmIyY2UzMzhmOWZjMDY5MjczNGQzZQ==
4
+ NDk5ZDBkYjAxZTRmNjAzNmY5NjgxNDI0Njc4Y2FhYjM0YTJkZDIzNA==
5
5
  data.tar.gz: !binary |-
6
- ZDJhZmQwMjZmMjEwMjExMWQ4YTY1MDI3NTc3ZmFjNzU4MzgxYzc5OA==
6
+ NGZiNWZiNTExMjBjNWVhMGU3NTczNjYzZGMzZjk2YzgxMWQyMzMwYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmE4YmYxN2JhNTYwMTBiYmFmZmM0MmY4ZDM2YTFhN2U2NjdlMDZjMjUyYjRh
10
- YTkzMGZmYjg3Njk2M2NhODM0M2Q1NzBmY2NmMTgyYmJhZjEzMTEyMTVmYTA3
11
- ODBmMWY0N2UyZTgyZDM5N2E0ZDhhZmE4YTQ0OGRlZjczOWZmNDQ=
9
+ NTkyYmY5NmM0NmQ2NTQ3NDU5ZTRkZDFkOTM1ODg2MDA4MTIxNmJhNjM4NWEx
10
+ Njg5NWM1OWY4OTI0MzE1YTcwMTE2ZWQwMzc4NzUyOTBmNGUzZThkMjMxZjQ3
11
+ NzM2MGRkOTQ3YzI5YmY0NDZjNWNkYzBlZDFkODMyOGE1MDc0NzE=
12
12
  data.tar.gz: !binary |-
13
- NThjZDg0MTI4NDU2YmNhMDQ2NGQzNWE2MDI1ZDhmMWE0M2NhZWIyNDgwNDUx
14
- NzVmNTQzNGJlZGU4MjE2MGE2OTMzNWViMTgxM2NiNjhlOTAzODUzZjc5YzNm
15
- ZDAyM2ZlYjgyNTg3MGVjOWE1Y2Y2YjFiNWVmNTI3NTQ4MjQ0Mzk=
13
+ ZmZkNGE5ZGU4Yjg4OWEwZmZlNTYwODg2MDUzMjQ1MzVkNGUwZDFjNTYzYWJj
14
+ N2Q5MGMyYWU5ZTU0YmQ5OWRhMzExODJkYjIwMzVhMjRhMGE3MDE0Y2Q2N2Yy
15
+ MWFkNzU3YWNiZmQ3ZmRlMjQwZWM5ZjAxNmJjZDFkN2RmY2Q3NzQ=
data/CHANGES CHANGED
@@ -7,3 +7,7 @@
7
7
  == Version 1.0.1
8
8
 
9
9
  * Bug fix.
10
+
11
+ == Version 1.0.2
12
+
13
+ * Bug fix.
@@ -13,11 +13,9 @@ class TextInterpolator
13
13
  end
14
14
 
15
15
  def interpolate_string string, env={}
16
- string = string.gsub(/\#{/, '%{') if string.index(/\#\{/)
16
+ new_string = replace_special_symbols(string)
17
17
 
18
- string = interpolate_env_vars(string) if string.index('ENV[')
19
-
20
- StringIO.new(string).read % env
18
+ StringIO.new(new_string).read % env
21
19
  end
22
20
 
23
21
  def interpolate_io io, env={}
@@ -32,22 +30,16 @@ class TextInterpolator
32
30
  end
33
31
 
34
32
  def interpolate_hash hash
35
- pairs = hash.reduce({}) do |result, value|
33
+ env = hash.reduce({}) do |result, value|
36
34
  result[value[0]] = value[1]
37
35
 
38
36
  result
39
37
  end
40
38
 
41
39
  hash.each do |key, value|
42
- value = value.gsub(/\#/, '%') if value.index("#")
43
-
44
- hash[key] = StringIO.new(value).read % pairs
45
- end
46
-
47
- hash.each do |key, value|
48
- new_value = interpolate_env_vars value
40
+ new_value = replace_special_symbols(value)
49
41
 
50
- hash[key] = new_value if new_value
42
+ hash[key] = StringIO.new(new_value).read % env
51
43
  end
52
44
 
53
45
  hash
@@ -55,6 +47,15 @@ class TextInterpolator
55
47
 
56
48
  private
57
49
 
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
+
58
59
  def interpolate_env_vars value
59
60
  while value.index('ENV[')
60
61
  value = interpolate_env_var value
@@ -1,3 +1,3 @@
1
1
  class TextInterpolator
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -75,15 +75,5 @@ describe TextInterpolator do
75
75
  expect(result[:dest_dir]).to eq '/usr/local/oracle/instantclient_11_2'
76
76
  expect(result[:basic_zip]).to eq 'downloads/instantclient-basic-macos.x64-11.2.0.4.0.zip'
77
77
  end
78
-
79
- it "test" do
80
- env = {:host=>"localhost", :user=>"ashvets", :home=>"/Users/ashvets", :ruby_home=>"/Users/ashvets/.rvm/rubies/ruby-1.9.3-p545", :oracle_base=>"/usr/local/oracle", :oracle_version=>"11.2.0.4.0", :ruby_oci_version=>"2.1.7", :tns_admin_dir=>"/usr/local/oracle/network/admin", :src_dir=>"downloads", :dest_dir=>"/usr/local/oracle/instantclient_11_2", :basic_zip=>"downloads/instantclient-basic-macos.x64-11.2.0.4.0.zip", :sdk_zip=>"downloads/instantclient-sdk-macos.x64-11.2.0.4.0.zip", :sqlplus_zip=>"downloads/instantclient-sqlplus-macos.x64-11.2.0.4.0.zip"}
81
-
82
- s = "\necho \"Installing ruby-oci8 gem...\"\n\nORACLE_BASE=\"%{oracle_base}\"\nDYLD_LIBRARY_PATH=\"%{dest_dir}\"\nTNS_ADMIN=\"%{tns_admin_dir}\"\nNLS_LANG='.UTF8'\n\nENV_VARS=\"ORACLE_BASE=$ORACLE_BASE DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH TNS_ADMIN=$TNS_ADMIN NLS_LANG=$NLS_LANG\"\n\n%env $ENV_VARS bash -c 'gem install ruby-oci8 -v %{ruby_oci_version}'\n\n\n"
83
-
84
- result = subject.interpolate s, env
85
-
86
- p result
87
- end
88
78
  end
89
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets