abstract_command 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c36ad254ea1fcfe9f031d3f32e2d1f394c9c8b604b6acc4fe800ee56f5bac43c
4
- data.tar.gz: b0ff9b75a15365439c8a2705aa26decab42689ba1325fa47aa8d81f3d8689b2e
3
+ metadata.gz: d7d962f4d270e21692dc110cd7b1ad2fef5b53be412a3c647f480747ba5f78e0
4
+ data.tar.gz: 610073595394448b95394c5f778bc7768afe88c19040aa9b45169cb3a49ef462
5
5
  SHA512:
6
- metadata.gz: aec380b77cb3d78b722a2bc8e894af21c3eb5ea1924302df029071af709f277466ffbb51fe5b90835b2e46c4a63d7c8acaccd348cd1e59be281215747f2fc674
7
- data.tar.gz: 2fd99ae104f6116967103e53c826b70b76376541c57c623a085049419f9867fabad317613cce4e064e98c1087c82c85dca27a1cc32199412b79eace47173a88b
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+)(>)/)
@@ -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 % bindings)
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.5
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: []