text-interpolator 1.1.3 → 1.1.4

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
- MjdmMGU5OTNkMDYwZGFkN2JkYzdhNWVkZDY2MjIyZTRlYmMyNDAzMg==
4
+ YzM4N2Q0MmFiMWM0YjVmM2U1ODAxYWRmZGRkNzA0ZTQ2NmMzMGIwNA==
5
5
  data.tar.gz: !binary |-
6
- NTViZDRiMTQ0NzkxMDhkM2Y5ZGIwNWM3YjM5ODM3NTZlNzY3ZDIxNQ==
6
+ YmFiYzM1YTViMzgzOGE1ZjEzZTdkZDkwZjQxY2ZhYjM5MjE1YzgyOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDRhZTVmYzNkYWY2OGQzNTg4ZTgzYjNmOWQwZmEyMWRkZWNjYzc2NmRhMDlm
10
- YjAwYzYyYmRjY2EyMDQwNDE5M2YxMjFhYTIxNDkxYzE4ZjYyOTgzNDY2ZjBi
11
- MDk4ZWE4NDMyZGJkNmY0Y2QwYzNjNmM2M2ZjZmExNjM3ZDg1MmI=
9
+ OTc4YWYyMzNmMmJjY2E4YTZiOGQyZDE4ODllYjA1NGU5ZjlhYjYzMzczOWYx
10
+ OWM5YWFiNGRjMzE5ZDhlYjE0ZmY2Mzc1YzU2ZjEwZGM2NjkyZjVhNDhjYWUy
11
+ MTJhMzM1NWU4NjFkZDYyNDRhNzg4MTMwNGNhM2M3YjY3N2Y0YWI=
12
12
  data.tar.gz: !binary |-
13
- ZWQ5NDM2M2UxZTcyMmQ5YjcxMDdiZTZkOGUwNjY4NTRjMDYzODE5ZjJiNWI0
14
- Njg2N2JlNDBkMTEzZjg4MzZiNGE4NTE3MjBmNTM1ZDZmZGI4MTkxNTU5MmZk
15
- ZGExOTg3MDEwMWIyMGFmMWNkYjUyOTEyMWIxMjkzZDU5NGQ3MzU=
13
+ NzdhOTJiMTBkOTljZmM2MGRmNGRkZGZmOTM4N2RkMGNkNjc3MWY0ODZjMWE5
14
+ MWQxN2RhNGUyMjU3ZGQwMzE2MTBhN2U1YzU1MWZlNDY2YWE5ZThjNTNiZGVj
15
+ MjM2ZTA4NzdmNzBlNWI5YjJjODg2N2VlN2NiYzEzMDQ3Nzg2NmQ=
data/CHANGES CHANGED
@@ -38,4 +38,8 @@
38
38
 
39
39
  == Version 1.1.3
40
40
 
41
- * Bug fix.
41
+ * Bug fix.
42
+
43
+ == Version 1.1.4
44
+
45
+ * Bug fixes.
@@ -25,10 +25,14 @@ class TextInterpolator
25
25
  def interpolate_string string, env={}
26
26
  clear_errors
27
27
 
28
+ env = symbolize_keys env
29
+
28
30
  value = interpolate_system_variable string
29
31
 
32
+ var_table = build_variables_table(env) # one-dimensional collection of variables
33
+
30
34
  begin
31
- new_value = interpolate_variable value, env
35
+ new_value = interpolate_variable value, var_table
32
36
  rescue KeyError => e
33
37
  new_value = string
34
38
  errors << e.message
@@ -169,4 +173,22 @@ class TextInterpolator
169
173
  StringIO.new(new_value).read % env
170
174
  end
171
175
 
176
+ def symbolize_keys hash
177
+ new_hash = {}
178
+
179
+ hash.each do |key, value|
180
+ new_value = if value.kind_of? String
181
+ value
182
+ elsif value.kind_of? Hash
183
+ symbolize_keys value
184
+ else
185
+ value
186
+ end
187
+
188
+ new_hash[key.to_sym] = new_value
189
+ end
190
+
191
+ new_hash
192
+ end
193
+
172
194
  end
@@ -1,3 +1,3 @@
1
1
  class TextInterpolator
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end
@@ -5,16 +5,22 @@ require 'text_interpolator'
5
5
  describe TextInterpolator do
6
6
 
7
7
  describe "#interpolate_string" do
8
- it "interpolates string with %{} tokens" do
9
- env = {name1: 'name1', name2: 'name2'}
8
+ it "interpolates string with %{} symbol tokens" do
9
+ env = {name1: 'value1', name2: 'value2'}
10
10
 
11
- expect(subject.interpolate_string "%{name1}, %{name2}", env).to eq "name1, name2"
11
+ expect(subject.interpolate_string "%{name1}, %{name2}", env).to eq "value1, value2"
12
+ end
13
+
14
+ it "interpolates string with %{} string tokens" do
15
+ env = {'name1' => 'value1', 'name2' => 'value2'}
16
+
17
+ expect(subject.interpolate_string "%{name1}, %{name2}", env).to eq "value1, value2"
12
18
  end
13
19
 
14
20
  it "interpolates string with '#{}' token" do
15
- env = {name1: 'name1', name2: 'name2'}
21
+ env = {name1: 'value1', name2: 'value2'}
16
22
 
17
- expect(subject.interpolate_string '#{name1}, #{name2}', env).to eq "name1, name2"
23
+ expect(subject.interpolate_string '#{name1}, #{name2}', env).to eq "value1, value2"
18
24
  end
19
25
 
20
26
  it "interpolates string with ENV token" do
@@ -25,28 +31,46 @@ describe TextInterpolator do
25
31
  end
26
32
 
27
33
  it "interpolates string with ENV token and white space" do
28
- ENV['name1'] = 'name1'
29
- ENV['name2'] = 'name2'
34
+ ENV['name1'] = 'value1'
35
+ ENV['name2'] = 'value2'
30
36
 
31
- expect(subject.interpolate_string " ENV['name1'], ENV['name2']").to eq " name1, name2"
37
+ expect(subject.interpolate_string " ENV['name1'], ENV['name2']").to eq " value1, value2"
32
38
  end
33
39
 
34
40
  it "interpolates string with mixed tokens" do
35
- env = {name1: 'name1', name2: 'name2'}
36
- ENV['name3'] = 'name3'
41
+ env = {name1: 'value1', name2: 'value2'}
42
+ ENV['name3'] = 'value3'
43
+
44
+ expect(subject.interpolate_string '#{name1}, #{name2}, ENV[\'name3\']', env).to eq "value1, value2, value3"
45
+ end
46
+
47
+ it "interpolates string with multi-level tokens" do
48
+ env = {"name1" => 'value1', 'level2.name2' => 'value2'}
37
49
 
38
- expect(subject.interpolate_string '#{name1}, #{name2}, ENV[\'name3\']', env).to eq "name1, name2, name3"
50
+ result = subject.interpolate_string '#{name1}, #{level2.name2}', env
51
+
52
+ expect(subject.errors).to be_empty
53
+ expect(result).to eq "value1, value2"
54
+ end
55
+
56
+ it "interpolates string with multi-level tokens (part 2)" do
57
+ env = {name1: 'value1', level2: {name2: 'value2'}}
58
+
59
+ result = subject.interpolate_string '#{name1}, #{level2.name2}', env
60
+
61
+ expect(subject.errors).to be_empty
62
+ expect(result).to eq "value1, value2"
39
63
  end
40
64
  end
41
65
 
42
66
  describe "#interpolate_io" do
43
67
  it "interpolates io stream" do
44
- env = {name1: 'name1', name2: 'name2'}
45
- ENV['name3'] = 'name3'
68
+ env = {name1: 'value1', name2: 'value2'}
69
+ ENV['name3'] = 'value3'
46
70
 
47
71
  io = StringIO.new '#{name1}, #{name2}, ENV[\'name3\']'
48
72
 
49
- expect(subject.interpolate_io io, env).to eq "name1, name2, name3"
73
+ expect(subject.interpolate_io io, env).to eq "value1, value2, value3"
50
74
  end
51
75
  end
52
76
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text-interpolator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemspec_deps_gen