simple-spawn 0.1.0 → 0.1.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. data/lib/simple/spawn.rb +30 -15
  2. data/simple-spawn.gemspec +1 -1
  3. metadata +1 -1
data/lib/simple/spawn.rb CHANGED
@@ -11,8 +11,8 @@ module Simple
11
11
  tmp_out = $stdout
12
12
  pipe = []
13
13
 
14
- commands.each_with_index do |command, index|
15
- program, *args = Shellwords.shellsplit(command)
14
+ commands.each_with_index do |cmd, index|
15
+ program, *args = Shellwords.shellsplit(cmd)
16
16
 
17
17
  if index+1 < commands.size
18
18
  pipe = IO.pipe
@@ -21,7 +21,7 @@ module Simple
21
21
  tmp_out = $stdout
22
22
  end
23
23
 
24
- spawn_program(program, *args, tmp_out, tmp_in)
24
+ Spawner.new(program, *args, tmp_out, tmp_in).exec!
25
25
 
26
26
  tmp_out.close unless tmp_out == $stdout
27
27
  tmp_in.close unless tmp_in == $stdin
@@ -35,20 +35,35 @@ module Simple
35
35
  line.scan( /([^"'|]+)|["']([^"']+)["']/ ).flatten.compact
36
36
  end
37
37
 
38
- def spawn_program(program, *args, tmp_out, tmp_in)
39
- fork {
40
- unless tmp_out == $stdout
41
- $stdout.reopen(tmp_out)
42
- tmp_out.close
43
- end
38
+ class Spawner
44
39
 
45
- unless tmp_in == $stdin
46
- $stdin.reopen(tmp_in)
47
- tmp_in.close
48
- end
40
+ attr_reader :program, :args, :tmp_out, :tmp_in
49
41
 
50
- exec program, *args
51
- }
42
+ def initialize program, *args, tmp_out, tmp_in
43
+ @tmp_out = tmp_out
44
+ @tmp_in = tmp_in
45
+ @program = program
46
+ @args = *args
47
+ end
48
+
49
+ def exec!
50
+ fork {
51
+ close_out unless tmp_out == $stdout
52
+ close_in unless tmp_in == $stdin
53
+ exec program, *args
54
+ }
55
+ end
56
+
57
+ private
58
+
59
+ def close_out
60
+ $stdout.reopen(tmp_out)
61
+ tmp_out.close
62
+ end
63
+ def close_in
64
+ $stdin.reopen(tmp_in)
65
+ tmp_in.close
66
+ end
52
67
  end
53
68
  end
54
69
  end
data/simple-spawn.gemspec CHANGED
@@ -11,5 +11,5 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = gem.files.grep(%r{^test/})
12
12
  gem.name = 'simple-spawn'
13
13
  gem.require_paths = ["lib"]
14
- gem.version = '0.1.0'
14
+ gem.version = '0.1.1'
15
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-spawn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: