abstract_command 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/abstract_command.rb +37 -6
  3. metadata +5 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d617d4126a76b14a03c717486abfd7bb312459f82712e7c29735034a4722b135
4
- data.tar.gz: 901a3d8c94f25433cd4ddde11c045b35ce7b8c88f4f3b60680a53ada89eb8840
3
+ metadata.gz: 9ba889bea5d22de45ed1a51494769807bc332b09cda2db7548eb375f5b5c7d4d
4
+ data.tar.gz: 138147f976e27b00925e9fe5627ff895400931b6924dc64473880ba81a53e937
5
5
  SHA512:
6
- metadata.gz: 275e35c4ef65c964cf089a294df11bbd68893975668896a40eabaa47e0883dbf4534cb7aba48d7db35af987c0a0dad932783336dec4b01aa527ea85a4a271a23
7
- data.tar.gz: 7a4acaadf65161a3ca28ff7acdf415240dac8952362a8942a4e8956af9f0fb0c936724d5021c004a7bb236149d850a6357f5ec7365636c7202b62c896678287b
6
+ metadata.gz: 8e121b83d22e0ccd997dd0ca53e0f25c68a6466dc2e2e16cca2fa8ef1bdfbd70bb453149ab4476d82bff9472c5dfaff9fcd1bbaa97b59026ed2d33767d09a2b9
7
+ data.tar.gz: 6325953eb38c30498e6d5af206191bcdef03228959936d673fb9c4e0c6681c20733055e9141aacb7e80768c88c5f10e20ce9db15a39b514da55d4321f3bd7f8c
@@ -4,18 +4,41 @@ require 'shellwords'
4
4
  # Shell Command Abstraction.
5
5
  #
6
6
  # Hides away all the details to generate a command.
7
- # And privides an easy interface to interact with shell commands as if
7
+ # And provides an easy interface to interact with shell commands as if
8
8
  # they were objects.
9
9
  #
10
10
  # This is good for the following reasons:
11
11
  #
12
- # 1. Stadardization.
13
- # 2. Simplicity of code.
14
- # 3. Reduces smells in methods that interpolate values.
15
- # 4. Provides an elegant way to interact shell objects.
16
- # 5. Secure ensures that shell commands are executed safely.
12
+ # - Enforces standardization.
13
+ # - Enforces separation of command definition and consumption.
14
+ # - Enforces configuration over code.
15
+ # - Enforces configuration over refactoring.
16
+ # - Enforces simple shell-command definition.
17
+ # - Enforces automatic sanitization of variables that get interpolated.
18
+ # - Provides a simple Object Oriented Interface.
19
+ # - Provides a scope for variables that belong to the command.
20
+ # - Provides getters and setter for every interpolation in command.
21
+ # - Provides a neat interface that plugs to data structures transparently.
22
+ # - Avoids methods with many arguments.
23
+ # - Avoids changes in the standared libarary: system, backtick, etc.
24
+ #
17
25
  class AbstractCommand
18
26
 
27
+ # before ruby 1.9.1 the format method does not support
28
+ # the syntax we want, so we have a simplified version of
29
+ # format for older versions of ruby.
30
+ # its placed in the AbstractCommand class because we want
31
+ # to avoid possible collisions for people requiring our code.
32
+ # It can live on a better place though..
33
+ class Formatter
34
+ REGEXP = /(%<)(\S+)(>\w)/
35
+ def self.format(template, params)
36
+ template.gsub(REGEXP) do
37
+ params[$2.to_sym]
38
+ end
39
+ end
40
+ end
41
+
19
42
  # '%<name>s'.scan(/(%<)(\w+)(>)/)
20
43
  # => [["%<", "name", ">"]]
21
44
  VARIABLE_REGEX = /(%<)(\w+)(>)/
@@ -51,6 +74,14 @@ class AbstractCommand
51
74
  format(template, bindings)
52
75
  end
53
76
 
77
+ def format(template, bindings)
78
+ if RUBY_VERSION <= '1.9.1'
79
+ Formatter.format(template, bindings)
80
+ else
81
+ super(template, bindings)
82
+ end
83
+ end
84
+
54
85
  def system
55
86
  super(to_s)
56
87
  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.6
4
+ version: 0.0.8
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
@@ -21,7 +21,7 @@ homepage: http://rubygems.org/gems/abstract_command
21
21
  licenses:
22
22
  - MIT
23
23
  metadata: {}
24
- post_install_message:
24
+ post_install_message:
25
25
  rdoc_options: []
26
26
  require_paths:
27
27
  - lib
@@ -36,9 +36,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  requirements: []
39
- rubyforge_project:
40
- rubygems_version: 2.7.6
41
- signing_key:
39
+ rubygems_version: 3.3.7
40
+ signing_key:
42
41
  specification_version: 4
43
42
  summary: Shell Command Abstraction
44
43
  test_files: []