abstract_command 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/abstract_command.rb +51 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c490e099be6c9632b79162671f8bfb6f47237badc06fca8bed45f9ce5902d73
4
+ data.tar.gz: 5756e256ee89e5efc473be853008c32b3ada1e616c3b58fd6964f17527871eb8
5
+ SHA512:
6
+ metadata.gz: 50ab258f9266adee224dc2c46e6d44b705f916e68bbcf1f1607f806303ad8d48be3a199ddfec91f40965cfcc843361775f295640f8ab2045bd56bf7204663ed1
7
+ data.tar.gz: 975bcd6d69aa87cee7cf61da2a4d0bcb7fe1d377926c8bdf86c0ed6feaf104eb90dd9159b3ab53ea79ce7c31228382594dacbb45e0df2f7a1844aac9a8fe5556
@@ -0,0 +1,51 @@
1
+ # Shell Command Abstraction.
2
+ #
3
+ # Hides away all the details to generate a command.
4
+ # And privides an easy interface to interact with shell commands as if
5
+ # they were objects.
6
+ #
7
+ # This is good for the following reasons:
8
+ #
9
+ # 1. Stadardization.
10
+ # 2. Simplicity of code.
11
+ # 3. Reduces smells in methods that interpolate values.
12
+ class AbstractCommand
13
+ # '%<name>s'.scan(/(%<)(\w+)(>)/)
14
+ # => [["%<", "name", ">"]]
15
+ VARIABLE_REGEX = /(%<)(\w+)(>)/
16
+
17
+ def template
18
+ raise 'must implement'
19
+ end
20
+
21
+ def variables
22
+ result = []
23
+ template.scan(VARIABLE_REGEX).each do |variable|
24
+ result.push(variable[1])
25
+ end
26
+ result
27
+ end
28
+
29
+ def initialize
30
+ variables.each do |variable|
31
+ self.class.send(:attr_accessor, variable.to_sym)
32
+ end
33
+ end
34
+
35
+ def to_s
36
+ bindings = {}
37
+ variables.each do |variable|
38
+ value = instance_variable_get("@#{variable}")
39
+ bindings[variable.to_sym] = value
40
+ end
41
+ format(template % bindings)
42
+ end
43
+
44
+ def system
45
+ Kernel.system(to_s)
46
+ end
47
+
48
+ def backtick
49
+ `#{to_s}`
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abstract_command
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kazuyoshi Tlacaelel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: An Abstraction that lets you interact with commands as if they were objects
14
+ email: kazu.dev@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/abstract_command.rb
20
+ homepage: http://rubygems.org/gems/abstract_command
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.7.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Shell Command Abstraction
44
+ test_files: []