abstract_command 0.0.5 → 0.0.7
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 +24 -7
- data/lib/formatter.rb +17 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7d962f4d270e21692dc110cd7b1ad2fef5b53be412a3c647f480747ba5f78e0
|
4
|
+
data.tar.gz: 610073595394448b95394c5f778bc7768afe88c19040aa9b45169cb3a49ef462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48d1dc40f33242eb194071aab72619ada6a4b2422308e856076e0a1f0e0cce024d2aa254124fe0ebc4518043cb14997be0d9ad400672cb23542669c61a3f0235
|
7
|
+
data.tar.gz: ad6414be1b6f4aad84282b6f75293eac55d7e07c268dde7edc57481ec8a996c5d3aa0c694127f34f10bcecb0ad0e16e7c3035077c348477a7bb87f8318b4165e
|
data/lib/abstract_command.rb
CHANGED
@@ -1,19 +1,28 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'shellwords'
|
3
|
+
require './lib/formatter.rb'
|
3
4
|
|
4
5
|
# Shell Command Abstraction.
|
5
6
|
#
|
6
7
|
# Hides away all the details to generate a command.
|
7
|
-
# And
|
8
|
+
# And provides an easy interface to interact with shell commands as if
|
8
9
|
# they were objects.
|
9
10
|
#
|
10
11
|
# This is good for the following reasons:
|
11
12
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
13
|
+
# - Enforces standardization.
|
14
|
+
# - Enforces separation of command definition and consumption.
|
15
|
+
# - Enforces configuration over code.
|
16
|
+
# - Enforces configuration over refactoring.
|
17
|
+
# - Enforces simple shell-command definition.
|
18
|
+
# - Enforces automatic sanitization of variables that get interpolated.
|
19
|
+
# - Provides a simple Object Oriented Interface.
|
20
|
+
# - Provides a scope for variables that belong to the command.
|
21
|
+
# - Provides getters and setter for every interpolation in command.
|
22
|
+
# - Provides a neat interface that plugs to data structures transparently.
|
23
|
+
# - Avoids methods with many arguments.
|
24
|
+
# - Avoids changes in the standared libarary: system, backtick, etc.
|
25
|
+
#
|
17
26
|
class AbstractCommand
|
18
27
|
|
19
28
|
# '%<name>s'.scan(/(%<)(\w+)(>)/)
|
@@ -48,7 +57,15 @@ class AbstractCommand
|
|
48
57
|
value = instance_variable_get("@#{variable}")
|
49
58
|
bindings[variable.to_sym] = "#{value}".shellescape
|
50
59
|
end
|
51
|
-
format(template
|
60
|
+
format(template, bindings)
|
61
|
+
end
|
62
|
+
|
63
|
+
def format(template, bindings)
|
64
|
+
if RUBY_VERSION <= '1.9.1'
|
65
|
+
Formatter.format(template, bindings)
|
66
|
+
else
|
67
|
+
super(template, bindings)
|
68
|
+
end
|
52
69
|
end
|
53
70
|
|
54
71
|
def system
|
data/lib/formatter.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
# before ruby 1.9.1 the format method does not support
|
3
|
+
# the syntax we want, so we have a simplified version of
|
4
|
+
# format for older versions of ruby.
|
5
|
+
# its placed in the AbstractCommand class because we want
|
6
|
+
# to avoid possible collisions for people requiring our code.
|
7
|
+
# It can live on a better place though..
|
8
|
+
class AbstractCommand
|
9
|
+
class Formatter
|
10
|
+
REGEXP = /(%<)(\S+)(>\w)/
|
11
|
+
def self.format(template, params)
|
12
|
+
template.gsub(REGEXP) do
|
13
|
+
params[$2.to_sym]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstract_command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyoshi Tlacaelel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-10-22 00:00:00.000000000 Z
|
@@ -17,11 +17,12 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/abstract_command.rb
|
20
|
+
- lib/formatter.rb
|
20
21
|
homepage: http://rubygems.org/gems/abstract_command
|
21
22
|
licenses:
|
22
23
|
- MIT
|
23
24
|
metadata: {}
|
24
|
-
post_install_message:
|
25
|
+
post_install_message:
|
25
26
|
rdoc_options: []
|
26
27
|
require_paths:
|
27
28
|
- lib
|
@@ -36,9 +37,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
37
|
- !ruby/object:Gem::Version
|
37
38
|
version: '0'
|
38
39
|
requirements: []
|
39
|
-
|
40
|
-
|
41
|
-
signing_key:
|
40
|
+
rubygems_version: 3.3.7
|
41
|
+
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: Shell Command Abstraction
|
44
44
|
test_files: []
|