abstract_command 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d617d4126a76b14a03c717486abfd7bb312459f82712e7c29735034a4722b135
4
- data.tar.gz: 901a3d8c94f25433cd4ddde11c045b35ce7b8c88f4f3b60680a53ada89eb8840
3
+ metadata.gz: d7d962f4d270e21692dc110cd7b1ad2fef5b53be412a3c647f480747ba5f78e0
4
+ data.tar.gz: 610073595394448b95394c5f778bc7768afe88c19040aa9b45169cb3a49ef462
5
5
  SHA512:
6
- metadata.gz: 275e35c4ef65c964cf089a294df11bbd68893975668896a40eabaa47e0883dbf4534cb7aba48d7db35af987c0a0dad932783336dec4b01aa527ea85a4a271a23
7
- data.tar.gz: 7a4acaadf65161a3ca28ff7acdf415240dac8952362a8942a4e8956af9f0fb0c936724d5021c004a7bb236149d850a6357f5ec7365636c7202b62c896678287b
6
+ metadata.gz: 48d1dc40f33242eb194071aab72619ada6a4b2422308e856076e0a1f0e0cce024d2aa254124fe0ebc4518043cb14997be0d9ad400672cb23542669c61a3f0235
7
+ data.tar.gz: ad6414be1b6f4aad84282b6f75293eac55d7e07c268dde7edc57481ec8a996c5d3aa0c694127f34f10bcecb0ad0e16e7c3035077c348477a7bb87f8318b4165e
@@ -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 privides an easy interface to interact with shell commands as if
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
- # 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.
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+)(>)/)
@@ -51,6 +60,14 @@ class AbstractCommand
51
60
  format(template, bindings)
52
61
  end
53
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
69
+ end
70
+
54
71
  def system
55
72
  super(to_s)
56
73
  end
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.6
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
- rubyforge_project:
40
- rubygems_version: 2.7.6
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: []