background_process 1.2 → 1.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.
data/.gemtest ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ background_process (1.3)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rake (0.8.7)
11
+ rspec (2.5.0)
12
+ rspec-core (~> 2.5.0)
13
+ rspec-expectations (~> 2.5.0)
14
+ rspec-mocks (~> 2.5.0)
15
+ rspec-core (2.5.1)
16
+ rspec-expectations (2.5.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.5.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ background_process!
25
+ rake
26
+ rspec (= 2.5.0)
data/README.textile CHANGED
@@ -1,8 +1,8 @@
1
1
  h1. Background Process
2
2
 
3
3
  This is like popen4, but provides several convenience methods for interacting
4
- with the process. It only works on UNIX and Ruby implementations that support
5
- fork and native UNIX I/O streams.
4
+ with the process. It only works on POSIX and Ruby implementations that support
5
+ fork and native POSIX I/O streams.
6
6
 
7
7
  "Click here for Complete Documentation":http://rdoc.info/projects/timcharper/background_process
8
8
 
@@ -17,7 +17,7 @@ process.exitstatus # => 1
17
17
  </pre>
18
18
 
19
19
  <pre>
20
- process = BackgroundProcess.run("sh -c 'sleep 1; exit 1'")
20
+ process = BackgroundProcess.run("sh", "-c", "sleep 1; exit 1")
21
21
  process.kill("KILL") # => true
22
22
  process.running? # => false
23
23
  process.exitstatus # => nil
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all examples"
5
+ Spec::Rake::SpecTask.new('spec') do |t|
6
+ t.spec_files = FileList['spec/**/*.rb']
7
+ end
8
+
9
+ desc "Default Task"
10
+ task :default => [ :spec ]
@@ -1,3 +1,4 @@
1
+ require 'timeout'
1
2
  require File.dirname(__FILE__) + "/background_process/background_process"
2
3
  require File.dirname(__FILE__) + "/background_process/pty_background_process"
3
4
  require File.dirname(__FILE__) + "/background_process/io_helpers"
@@ -21,8 +21,8 @@ class BackgroundProcess
21
21
  # If you can't control the program and have it explicitly flush its output when it
22
22
  # should, or you can't tell the streams to run in sync mode, see
23
23
  # PTYBackgroundProcess.run for a workaround.
24
- def self.run(command)
25
- command = sanitize_params(command) if command.is_a?(Array)
24
+ def self.run(*command_with_args)
25
+ command = sanitize_command(command_with_args)
26
26
  child_stdin, parent_stdin = IO::pipe
27
27
  parent_stdout, child_stdout = IO::pipe
28
28
  parent_stderr, child_stderr = IO::pipe
@@ -99,8 +99,10 @@ class BackgroundProcess
99
99
 
100
100
  protected
101
101
  # It's protected. What do you care? :P
102
- def self.sanitize_params(params)
103
- params.map { |p| p.gsub(' ', '\ ') }.join(" ")
102
+ def self.sanitize_command(*args)
103
+ command_and_args = args.flatten
104
+ return command_and_args.first if command_and_args.length == 1
105
+ command_and_args.map { |p| p.gsub(' ', '\ ') }.join(" ")
104
106
  end
105
107
 
106
108
  def select_streams(which)
@@ -11,7 +11,8 @@ class PTYBackgroundProcess < BackgroundProcess
11
11
  # * You can't get the exit status
12
12
  # * When the process dies, whatever output you haven't read yet is lost.
13
13
  # * stderr is merged into stdout
14
- def self.run(command)
14
+ def self.run(*command_with_args)
15
+ command = sanitize_command(command_with_args)
15
16
  thread = Thread.new do # why run PTY separate thread? When a PTY instance
16
17
  # dies, it raises PTY::ChildExited on the thread that
17
18
  # spawned it, interrupting whatever happens to be
@@ -18,6 +18,12 @@ describe PTYBackgroundProcess do
18
18
  process.stdin.puts "exit"
19
19
  process.wait
20
20
  end
21
+
22
+ it "allows you to pass an array of args, which are automatically sanitized" do
23
+ process = PTYBackgroundProcess.run("sh", "-c", "echo hi")
24
+ process.stdout.gets.chomp.should == "hi"
25
+ end
26
+
21
27
  end
22
28
 
23
29
  describe "#exitstatus" do
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: background_process
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 9
5
+ prerelease:
5
6
  segments:
6
7
  - 1
7
- - 2
8
- version: "1.2"
8
+ - 3
9
+ version: "1.3"
9
10
  platform: ruby
10
11
  authors:
11
12
  - Tim Harper
@@ -13,10 +14,39 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-04-28 00:00:00 -06:00
17
+ date: 2011-05-19 00:00:00 -06:00
17
18
  default_executable:
18
- dependencies: []
19
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 27
29
+ segments:
30
+ - 2
31
+ - 5
32
+ - 0
33
+ version: 2.5.0
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
20
50
  description: A library for spawning and interacting with UNIX processes
21
51
  email:
22
52
  - timcharper+bp@gmail.com
@@ -30,6 +60,10 @@ extra_rdoc_files:
30
60
  files:
31
61
  - README.textile
32
62
  - MIT-LICENSE
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - Rakefile
66
+ - .gemtest
33
67
  - lib/background_process/background_process.rb
34
68
  - lib/background_process/io_helpers.rb
35
69
  - lib/background_process/pty_background_process.rb
@@ -49,23 +83,27 @@ rdoc_options:
49
83
  require_paths:
50
84
  - lib
51
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
52
87
  requirements:
53
88
  - - ">="
54
89
  - !ruby/object:Gem::Version
90
+ hash: 3
55
91
  segments:
56
92
  - 0
57
93
  version: "0"
58
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
59
96
  requirements:
60
97
  - - ">="
61
98
  - !ruby/object:Gem::Version
99
+ hash: 3
62
100
  segments:
63
101
  - 0
64
102
  version: "0"
65
103
  requirements: []
66
104
 
67
105
  rubyforge_project: background_process
68
- rubygems_version: 1.3.6
106
+ rubygems_version: 1.5.0
69
107
  signing_key:
70
108
  specification_version: 3
71
109
  summary: background_process