cgi-spa 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/cgi-spa.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "cgi-spa"
5
- s.version = "0.3.4"
5
+ s.version = "0.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sam Ruby"]
@@ -23,3 +23,43 @@ def $x.script!(text)
23
23
  end
24
24
  end
25
25
  end
26
+
27
+ # execute a system command, echoing stdin, stdout, and stderr
28
+ def $x.system!(command, opts={})
29
+ require 'open3'
30
+ output_class = opts[:class] || {}
31
+ stdin = output_class[:stdin] || 'stdin'
32
+ stdout = output_class[:stdout] || 'stdout'
33
+ stderr = output_class[:stderr] || 'stderr'
34
+
35
+ $x.pre command, :class=>stdin unless opts[:echo] == false
36
+
37
+ semaphore = Mutex.new
38
+ Open3.popen3(command) do |pin, pout, perr|
39
+ [
40
+ Thread.new do
41
+ until pout.eof?
42
+ out_line = pout.readline.chomp
43
+ semaphore.synchronize { $x.pre out_line, :class=>stdout }
44
+ end
45
+ end,
46
+
47
+ Thread.new do
48
+ until perr.eof?
49
+ err_line = perr.readline.chomp
50
+ semaphore.synchronize { $x.pre err_line, :class=>stderr }
51
+ end
52
+ end,
53
+
54
+ Thread.new do
55
+ if opts[:stdin].respond_to? :read
56
+ require 'fileutils'
57
+ FileUtils.copy_stream opts[:stdin], pin
58
+ elsif opts[:stdin]
59
+ pin.write opts[:stdin].to_s
60
+ end
61
+ pin.close
62
+ end
63
+ ].each {|thread| thread.join}
64
+ end
65
+ end
@@ -1,8 +1,8 @@
1
1
  module CgiSpa
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 3
5
- TINY = 4
4
+ MINOR = 4
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cgi-spa
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
8
  - 4
10
- version: 0.3.4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Ruby