RunIt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +5 -0
- data/.rspec.example +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +7 -0
- data/README.md +62 -0
- data/README.rdoc +42 -0
- data/Rakefile +21 -0
- data/RunIt.gemspec +24 -0
- data/lib/RunIt.rb +70 -0
- data/spec/RunIt_spec.rb +72 -0
- data/spec/spec_helper.rb +17 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2JjMmEzZTk4NzdlM2M0Y2QwOTAzOTU3OTg5ZDljNzEyYzhiYzY2Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2QxNjU2ZmIwODNkYjgzYmE4ZjBhMDI4NTRlMWFiOTQ2NzY0MGZhOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTFlOTE5Y2YyZmU4OTgwY2YxMThhZTJkMTQ3NjA5OGU1ZTA5NTZhNDg0Mjg1
|
10
|
+
NGJkMWUwYzQ3NmUyNWY3NTJhYjhhOTQ5NTVlZGY4Njg1NzkyMjY1ZDM4ZGY2
|
11
|
+
YzZlYWE5MGU2YTM2ODBjMTRmYTExNjQwYTE3ZTE0MWQ2ZWY0NmY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDQxOGY1OTAyM2RhNTMxMjkzODc4NTM3M2Q4NTZiZjkxY2M2OTdhNTk3ZTZk
|
14
|
+
MGRjYzIzMmQzMjRlMjUxNzNhMTBiNzJkNmNlZThiZGYwMmIwY2NmNzA5OTYy
|
15
|
+
NDM5ZTFlMGIyODc0NmY3NWI1ODI1NGI2YWZjNzE5OWFmMzlhZmY=
|
data/.rspec.example
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
RunIt (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.4)
|
10
|
+
json (1.7.7)
|
11
|
+
rake (10.0.3)
|
12
|
+
rdoc (4.0.1)
|
13
|
+
json (~> 1.4)
|
14
|
+
rspec (2.13.0)
|
15
|
+
rspec-core (~> 2.13.0)
|
16
|
+
rspec-expectations (~> 2.13.0)
|
17
|
+
rspec-mocks (~> 2.13.0)
|
18
|
+
rspec-core (2.13.1)
|
19
|
+
rspec-expectations (2.13.0)
|
20
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
21
|
+
rspec-mocks (2.13.0)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
RunIt!
|
28
|
+
bundler (~> 1.3)
|
29
|
+
rake
|
30
|
+
rdoc
|
31
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 YOUR NAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# RunIt
|
2
|
+
|
3
|
+
A small wrapper class for Open3#popen3
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'RunIt'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install RunIt
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'RunIt'
|
22
|
+
runner = RunIt.new command
|
23
|
+
runner.run
|
24
|
+
if runner.result.success?
|
25
|
+
puts runner.output
|
26
|
+
else
|
27
|
+
$stderr.puts runner.error
|
28
|
+
end
|
29
|
+
|
30
|
+
Simple one-line thing:
|
31
|
+
|
32
|
+
raise "Could not list files!!" unless (runner = RunIt.new "/bin/ls").run
|
33
|
+
|
34
|
+
Full usage:
|
35
|
+
|
36
|
+
require 'RunIt'
|
37
|
+
|
38
|
+
input <<-LIPSUM
|
39
|
+
Lorem ipsum solar et domit.
|
40
|
+
Now is the winter of our discount tent.
|
41
|
+
For score and winning the game.
|
42
|
+
Every good boy deserves favour.
|
43
|
+
LIPSUM
|
44
|
+
|
45
|
+
runner = RunIt.new "/bin/cat", input, [], nil
|
46
|
+
if runner.run
|
47
|
+
# the output will be in an array
|
48
|
+
puts runner.output.join
|
49
|
+
else
|
50
|
+
STDERR.puts runner.error.join
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it [Githum repo](https://github.com/tamouse/RunIt)
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= RunIt - A wrapper class around Open3#popen3
|
2
|
+
|
3
|
+
Author:: Tamara Temple <tamouse@gmail.com>
|
4
|
+
Copyright:: Copyright (c) 2013 Tamara Temple Web Development
|
5
|
+
|
6
|
+
|
7
|
+
License:: mit, see LICENSE.txt
|
8
|
+
|
9
|
+
|
10
|
+
== SYNOPSIS
|
11
|
+
|
12
|
+
runner = RunIt.new(command, [input,] [output,] [error])
|
13
|
+
result = runner.run
|
14
|
+
puts runner.output if result
|
15
|
+
puts runner.error unless result
|
16
|
+
|
17
|
+
== DESCRIPTION
|
18
|
+
|
19
|
+
RunIt is a very simple class that wraps up the Open3#popen3 call. When you create the object, you specify the command to run as a string, optionally the input to the command (no input is given if nil), a type of receiver for the output of the command, but default this will be a string, and a type of receiver for the error output of the command, by default, also a string.
|
20
|
+
|
21
|
+
The #run method will execute the command, returning a Boolean denoting success or failure. The process status, standard output and standard error will be available from the runner object itself.
|
22
|
+
|
23
|
+
== Links
|
24
|
+
|
25
|
+
* {Source on Github}[https://github.com/tamouse/RunIt]
|
26
|
+
* RDoc[LINK TO RDOC.INFO]
|
27
|
+
|
28
|
+
== Install
|
29
|
+
|
30
|
+
gem install RunIt
|
31
|
+
|
32
|
+
== Examples
|
33
|
+
|
34
|
+
runner = RunIt.new("/bin/ls")
|
35
|
+
if runner.run
|
36
|
+
# process runner.output
|
37
|
+
else
|
38
|
+
STDERR.puts runner.error
|
39
|
+
end
|
40
|
+
|
41
|
+
== Contributing
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
gem 'rdoc' # we need the installed RDoc gem, not the system one
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
include Rake::DSL
|
6
|
+
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
# Put spec opts in a file named .rspec in root
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::RDocTask.new do |rd|
|
14
|
+
|
15
|
+
rd.main = "README.rdoc"
|
16
|
+
|
17
|
+
rd.rdoc_files.include("README.rdoc","lib/*.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => [:spec]
|
21
|
+
|
data/RunIt.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'RunIt'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "RunIt"
|
8
|
+
spec.version = RunIt::VERSION
|
9
|
+
spec.authors = ["Tamara Temple"]
|
10
|
+
spec.email = ["tamouse@gmail.com"]
|
11
|
+
spec.description = "A simple class to wrap Open3#popen3"
|
12
|
+
spec.summary = "A simple class to wrap Open3#popen3"
|
13
|
+
spec.homepage = "https://github.com/tamouse/RunIt"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency('rdoc')
|
24
|
+
end
|
data/lib/RunIt.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
= RUNIT.RB
|
4
|
+
|
5
|
+
*Author*:: Tamara Temple <tamara@tamaratemple.com>
|
6
|
+
*Since*:: 2013-04-23
|
7
|
+
*Copyright*:: (c) 2013 Tamara Temple Web Development
|
8
|
+
*License*:: MIT
|
9
|
+
|
10
|
+
== Description
|
11
|
+
|
12
|
+
A simple class to wrap Open3 to execute a command and return the result, stdout and stderr
|
13
|
+
|
14
|
+
=end
|
15
|
+
|
16
|
+
require 'open3'
|
17
|
+
require 'ostruct'
|
18
|
+
|
19
|
+
class RunIt
|
20
|
+
|
21
|
+
VERSION = "0.1.0"
|
22
|
+
|
23
|
+
attr_accessor :cmd, :input, :output, :error, :result
|
24
|
+
|
25
|
+
def initialize(cmd, input=nil, output=nil, error=nil)
|
26
|
+
|
27
|
+
self.cmd = cmd
|
28
|
+
self.output = output ||= ''
|
29
|
+
self.error = error ||= ''
|
30
|
+
|
31
|
+
# Input is a little more complicated
|
32
|
+
|
33
|
+
case input
|
34
|
+
when String ; self.input = input
|
35
|
+
when Array ; self.input = input.flatten.join("\n")
|
36
|
+
when NilClass ; self.input = nil
|
37
|
+
else self.input = input.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def run
|
43
|
+
|
44
|
+
begin
|
45
|
+
|
46
|
+
Open3.popen3(self.cmd) do |stdin, stdout, stderr, wait|
|
47
|
+
stdin.puts self.input unless self.input.nil?
|
48
|
+
stdin.close
|
49
|
+
until stdout.eof?
|
50
|
+
self.output << stdout.gets
|
51
|
+
end
|
52
|
+
until stderr.eof?
|
53
|
+
self.error << stderr.gets
|
54
|
+
end
|
55
|
+
self.result = wait.value
|
56
|
+
self.result.success?
|
57
|
+
end
|
58
|
+
|
59
|
+
rescue Exception => e
|
60
|
+
|
61
|
+
self.result = OpenStruct.new(:success? => false, :exitstatus => -1)
|
62
|
+
self.error << "#{cmd} raised an error: #{e.class}:#{e}"
|
63
|
+
false
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
data/spec/RunIt_spec.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
describe RunIt do
|
5
|
+
|
6
|
+
describe "/bin/ls" do
|
7
|
+
|
8
|
+
it "should return the list of files in an array" do
|
9
|
+
|
10
|
+
runner = RunIt.new "/bin/ls"
|
11
|
+
|
12
|
+
Dir.mktmpdir do |dir|
|
13
|
+
Dir.chdir(dir) do |dir|
|
14
|
+
%w[a b c d].each {|fn| FileUtils.touch(fn)}
|
15
|
+
runner.run.should be_true
|
16
|
+
runner.result.success?.should be_true
|
17
|
+
runner.output.should == "a\nb\nc\nd\n"
|
18
|
+
runner.error.should be_empty
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "/bin/cat" do
|
26
|
+
|
27
|
+
let(:input) { "Now is the winter of our discount tent." }
|
28
|
+
let(:runner) { RunIt.new "/bin/cat", input }
|
29
|
+
|
30
|
+
it "should return the same text as input" do
|
31
|
+
runner.run.should be_true
|
32
|
+
runner.result.success?.should be_true
|
33
|
+
runner.output.chomp.should == input
|
34
|
+
runner.error.should be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "array return" do
|
40
|
+
|
41
|
+
let(:input) {%w[Every good boy deserves favour]}
|
42
|
+
let(:runner) {RunIt.new "/bin/cat", input, [], nil}
|
43
|
+
|
44
|
+
it "should return the same text as input, but in an array" do
|
45
|
+
runner.run.should be_true
|
46
|
+
runner.result.success?.should be_true
|
47
|
+
runner.output.should be_a(Array)
|
48
|
+
runner.output.count.should == input.count
|
49
|
+
runner.output.map(&:chomp).should == input
|
50
|
+
runner.error.should be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "Bogus Command" do
|
56
|
+
|
57
|
+
let(:input) {"Why did the chicken cross the road? "}
|
58
|
+
let(:runner) {RunIt.new "/xyzzy/not_a_command_issit", input}
|
59
|
+
|
60
|
+
it "should give a false result" do
|
61
|
+
runner.run.should be_false
|
62
|
+
runner.result.success?.should be_false
|
63
|
+
runner.error.chomp.should_not be_empty
|
64
|
+
puts "Runner.error: " + runner.error.inspect
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: RunIt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tamara Temple
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A simple class to wrap Open3#popen3
|
70
|
+
email:
|
71
|
+
- tamouse@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec.example
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- README.rdoc
|
83
|
+
- Rakefile
|
84
|
+
- RunIt.gemspec
|
85
|
+
- lib/RunIt.rb
|
86
|
+
- spec/RunIt_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/tamouse/RunIt
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.0.0
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A simple class to wrap Open3#popen3
|
112
|
+
test_files:
|
113
|
+
- spec/RunIt_spec.rb
|
114
|
+
- spec/spec_helper.rb
|