abstract_command 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/abstract_command.rb +7 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e45a35935e9e0126e5e93e44656311a01ac2cf3b2f20c76b1b1179f9e24c3a9
|
4
|
+
data.tar.gz: 6743344c1ab9268d159286040382b36c979955e8dd020a3e85ee710bc5fe7dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b66f0431990fc522e8534f6dcd0d294f970cc0a168caddc9aabd6684d199bd1d23fd700daa4ec67c30f0c64f4c3abebac5584597e8d65a4e69703e6a9856d378
|
7
|
+
data.tar.gz: fa588040bcc5551a8d1c6aeb90f32a176fbfbfe920ef6617361d1310326d55213dcf200f281faac1a9d902f83ff1e2b11b23b35da3e23bd3ca73c99e33054d11
|
data/lib/abstract_command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
1
3
|
# Shell Command Abstraction.
|
2
4
|
#
|
3
5
|
# Hides away all the details to generate a command.
|
@@ -9,7 +11,10 @@
|
|
9
11
|
# 1. Stadardization.
|
10
12
|
# 2. Simplicity of code.
|
11
13
|
# 3. Reduces smells in methods that interpolate values.
|
14
|
+
# 4. Provides an elegant way to interact shell objects.
|
15
|
+
# 5. Secure ensures that shell commands are executed safely.
|
12
16
|
class AbstractCommand
|
17
|
+
|
13
18
|
# '%<name>s'.scan(/(%<)(\w+)(>)/)
|
14
19
|
# => [["%<", "name", ">"]]
|
15
20
|
VARIABLE_REGEX = /(%<)(\w+)(>)/
|
@@ -40,7 +45,7 @@ class AbstractCommand
|
|
40
45
|
bindings = {}
|
41
46
|
variables.each do |variable|
|
42
47
|
value = instance_variable_get("@#{variable}")
|
43
|
-
bindings[variable.to_sym] = value
|
48
|
+
bindings[variable.to_sym] = "#{value}".shellescape
|
44
49
|
end
|
45
50
|
format(template % bindings)
|
46
51
|
end
|
@@ -52,4 +57,5 @@ class AbstractCommand
|
|
52
57
|
def backtick
|
53
58
|
`#{to_s}`
|
54
59
|
end
|
60
|
+
|
55
61
|
end
|