rsystem 0.0.1 → 0.0.3

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
  SHA1:
3
- metadata.gz: e3e0bc843f56332982ab975f6ce6ce0363f3f500
4
- data.tar.gz: f869bd3bdcadf2036e5dee35703eea49a986ea55
3
+ metadata.gz: 3ed9e665a05086dbdd52905d68f25f5d44465d74
4
+ data.tar.gz: cbc2f064e1af691ac2430cce9699167f5cf6e8e9
5
5
  SHA512:
6
- metadata.gz: 4c4f3aee2a926c39bb61a180eca3715515a4c6a166c9d17d04ef2401ca31136d8f48cbc6450f9e54b41ba7103b328c83724aa128d482910a157183fa8b01fa74
7
- data.tar.gz: 3fdb5b500b0b22aa657258f3a64794d67bd492c0395f218a5494af3399cdd423d9e19115474e5fcc7bf807d23997dba8ec242a7df15709ab52b4b0a1e086e8d0
6
+ metadata.gz: dc00c0a07b41e33aa9c204a3e2905b661c007166ecca6189995534828b757c1be8e5504221ec24a5e9f10a845c55573b32654d3cbb8b6b7189752fc323b9add3
7
+ data.tar.gz: 703222eda2aae3c5cbca39caf8ec3e16551e2685b7f368d6b460824ff6f373ebae28d037422b24006b7e10503345ae86acd0c8a9f4a113c4e939466dabfe5dc1
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Miles Jordan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RSystem
2
2
 
3
- RSystem simply executes a system() call but it also echoes the command that it is about to execute to stdout.
3
+ RSystem simply executes a system() call but it also echoes the command that it is about to execute to stdout, and will raise an exception if the command does not return successfully.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,11 +20,25 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- `rsystem(<command>, echo=[true], options=[{}])`
23
+ Right now this gem just contains one statuc method.
24
24
 
25
- Simply using `rsystem(<command>` will execute the command and echo it, returning the return code of the command that is ran.
25
+ `RSystem::Runner:Run(<command>, [options={}])`
26
26
 
27
- The options that you can pass are the same as the ones listed for the [spawn](http://www.ruby-doc.org/core-2.2.0/Kernel.html#method-i-spawn) method in Ruby's Kernel module.
27
+ Simply using `RSystem::Runner:Run(<command>)` will execute the command and echo it, returning the return code of the command that is ran or raising an exception if it did not return successfully.
28
+
29
+ ### Options
30
+
31
+ There are two options specific to the `run` method that you can use, with the defaults listed here:
32
+
33
+ options{echo:true, raise_on_error: true}
34
+
35
+ The other options that you can pass are the same as the ones listed for the [spawn](http://www.ruby-doc.org/core-2.2.0/Kernel.html#method-i-spawn) method in Ruby's Kernel module.
36
+
37
+ ## Todo
38
+
39
+ - more tests
40
+ - output logging to a file
41
+ - stdout/stderr configuration
28
42
 
29
43
  ## Contributing
30
44
 
@@ -2,9 +2,28 @@ require "rsystem/version"
2
2
 
3
3
  module RSystem
4
4
  class Runner
5
- def self.run(command, echo=true, options={})
6
- puts "[#{Time.now}] Executing: #{command}" if echo
7
- system command, options
8
- end
5
+ def self.run(command, options={})
6
+
7
+ # Only set the default options of the haven't already been set
8
+ options[:echo] = true unless options.has_key?(:echo)
9
+ options[:raise_on_error] = true unless options.has_key?(:raise_on_error)
10
+
11
+ puts "[#{Time.now}] Executing: #{command}" if options[:echo]
12
+
13
+ # Remove custom options so we can pass the entire options hash to system()
14
+ sys_options = options.clone
15
+ sys_options.delete(:echo)
16
+ sys_options.delete(:raise_on_error)
17
+
18
+ ret = system(command, sys_options)
19
+ if !ret and options[:raise_on_error]
20
+ raise FailedExecutionException, "[#{Time.now}] Error: The executed command returned a failure code."
21
+ else
22
+ ret
23
+ end
24
+ end
25
+ end
26
+
27
+ class FailedExecutionException < Exception
9
28
  end
10
29
  end
@@ -1,3 +1,3 @@
1
1
  module RSystem
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,8 @@
1
+
2
+ require_relative '../lib/rsystem'
3
+
4
+ describe RSystem do
5
+ it "executes a valid command with no options" do
6
+ expect(RSystem::Runner::run 'echo "Hello, world!"').to eql true
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Jordan
@@ -75,12 +75,14 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
77
  - Gemfile
78
+ - LICENSE
78
79
  - LICENSE.txt
79
80
  - README.md
80
81
  - Rakefile
81
82
  - lib/rsystem.rb
82
83
  - lib/rsystem/version.rb
83
84
  - rsystem.gemspec
85
+ - spec/rsystem_spec.rb
84
86
  homepage: ''
85
87
  licenses:
86
88
  - MIT
@@ -106,4 +108,5 @@ signing_key:
106
108
  specification_version: 4
107
109
  summary: RSystem simply executes a system() call but it also echoes the command that
108
110
  it is about to execute to stdout.
109
- test_files: []
111
+ test_files:
112
+ - spec/rsystem_spec.rb