text-interpolator 1.1.1 → 1.1.2
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/README.md +41 -6
- data/lib/text_interpolator/text_interpolator.rb +2 -2
- data/lib/text_interpolator/version.rb +1 -1
- data/spec/text_interpolator_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGM0ZDI0YTQ4MWU1MmQyNWY1YTlmZjAyOTc1Y2M0ODdjYmJmMTE0Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Nzk1YmJlMjQ4MTFmODk2Y2I2ZTBiMTliZTU3ZDdmZjM1OTEwNDFiNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmViNDM5NjY4YmM2ZDQ4MDc4YTQ0ZTljMWQ1MWUzNWEyYjliOWI0Njk1NDcw
|
10
|
+
N2NmYWM0Njg1MmNiMTI3Nzg2MmQ0NWJlOTQ0ZDBlMDJhMGNiZTJkNzQ1OTAz
|
11
|
+
NmRmY2E2OGI3MGFkYzA4YTc2OTFlNzViZGZiMGNhNjEyNGQ3NTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjM0MTcwNjViZDVmOWI2MWM0NzI5YmFjMDgyNWY0ZTM4N2E5NGNlNTE0Y2I3
|
14
|
+
NWQwNDllN2U4MTBjNTI0NTQyZGRiODgwNDYzOGM2MGE5OTM1ZDhlNGE2MmQw
|
15
|
+
MTEyYmE4MTM3ZGU1YmVlODZiNDJlOGMwZWJmYjQ0YTIwOTVkZmM=
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Introduction
|
4
4
|
|
5
|
-
|
5
|
+
In ruby you have few options for variables interpolation:
|
6
6
|
|
7
7
|
- interpolation inside the string:
|
8
8
|
|
@@ -21,7 +21,9 @@ puts result # We have var1: some value 1 and var2: some value 2.
|
|
21
21
|
# some_template.erb
|
22
22
|
|
23
23
|
We have var1: <%= var1 %> and var2: <%= var2%>.
|
24
|
+
```
|
24
25
|
|
26
|
+
```ruby
|
25
27
|
# test.rb
|
26
28
|
|
27
29
|
require 'erb'
|
@@ -36,9 +38,8 @@ result = template.result(binding)
|
|
36
38
|
puts result # We have var1: some value 1 and var2: some value 2.
|
37
39
|
```
|
38
40
|
|
39
|
-
This library can be used for **interpolation inside file with string syntax**.
|
40
|
-
|
41
|
-
In order to achieve it library uses this ruby trick:
|
41
|
+
This library can be used for **interpolation inside file with string syntax**. In order to
|
42
|
+
achieve it this library uses one ruby trick:
|
42
43
|
|
43
44
|
```ruby
|
44
45
|
env = {var1: 'some value 1', var2: 'some value 2'}
|
@@ -52,14 +53,16 @@ puts result # We have var1: some value 1 and var2: some value 2.
|
|
52
53
|
|
53
54
|
## Usage
|
54
55
|
|
55
|
-
It's straightforward:
|
56
|
+
It's straightforward. Here is example of file interpolation:
|
56
57
|
|
57
58
|
```ruby
|
58
59
|
# some_template.txt
|
59
60
|
|
60
61
|
We have var1: #{var1} and var2: #{var2}.
|
61
62
|
We have var3: #{settings.var3} and var4: #{settings.var4}.
|
63
|
+
```
|
62
64
|
|
65
|
+
```ruby
|
63
66
|
# test.rb
|
64
67
|
|
65
68
|
require 'text_interpolator'
|
@@ -67,6 +70,7 @@ require 'text_interpolator'
|
|
67
70
|
env = {
|
68
71
|
var1: 'some value 1',
|
69
72
|
var2: 'some value 2',
|
73
|
+
|
70
74
|
settings: {
|
71
75
|
var3: 'some value 3',
|
72
76
|
var4: 'some value 4'
|
@@ -81,4 +85,35 @@ result = text_interpolator.interpolate template, env
|
|
81
85
|
|
82
86
|
puts result # We have var1: some value 1 and var2: some value 2.
|
83
87
|
# We have var3: some value 3 and var4: some value 4.
|
84
|
-
```
|
88
|
+
```
|
89
|
+
|
90
|
+
You can also interpolate hash on multiple levels:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
hash = {
|
94
|
+
host: 'localhost',
|
95
|
+
|
96
|
+
credentials: {
|
97
|
+
user: "some_user",
|
98
|
+
password: "some_password",
|
99
|
+
|
100
|
+
settings: {
|
101
|
+
user: "some_user2"
|
102
|
+
}
|
103
|
+
},
|
104
|
+
|
105
|
+
postgres: {
|
106
|
+
hostname: '#{host}',
|
107
|
+
user: '#{credentials.user}',
|
108
|
+
password: 'postgres'
|
109
|
+
},
|
110
|
+
|
111
|
+
mysql: {
|
112
|
+
user: '#{credentials.settings.user}',
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
result = subject.interpolate hash
|
117
|
+
|
118
|
+
p result
|
119
|
+
```
|
@@ -17,7 +17,7 @@ class TextInterpolator
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def interpolate_string string, env={}
|
20
|
-
@errors =
|
20
|
+
@errors = []
|
21
21
|
|
22
22
|
value = interpolate_system_variable string
|
23
23
|
|
@@ -31,7 +31,7 @@ class TextInterpolator
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def interpolate_hash hash
|
34
|
-
@errors =
|
34
|
+
@errors = []
|
35
35
|
|
36
36
|
content = interpolate_system_variables(hash)
|
37
37
|
|
@@ -95,7 +95,7 @@ describe TextInterpolator do
|
|
95
95
|
}
|
96
96
|
}
|
97
97
|
|
98
|
-
result = subject.
|
98
|
+
result = subject.interpolate hash
|
99
99
|
|
100
100
|
expect(result[:postgres][:user]).to eq hash[:credentials][:user]
|
101
101
|
expect(result[:mysql][:user]).to eq hash[:credentials][:settings][:user]
|
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.
|
4
|
+
version: 1.1.2
|
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-
|
11
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gemspec_deps_gen
|