em-systemcommand 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Em
2
2
  module Systemcommand
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -9,6 +9,9 @@ module EventMachine
9
9
  class SystemCommand
10
10
  include EM::SystemCommand::PipeHandler
11
11
  include EM::Deferrable
12
+ extend Forwardable
13
+
14
+ def_delegators :@command, :<<, :add
12
15
 
13
16
  pipe_handler :stdin, EM::SystemCommand::Pipe
14
17
  pipe_handler :stdout, EM::SystemCommand::Pipe
@@ -16,6 +19,20 @@ module EventMachine
16
19
 
17
20
  attr_accessor :pipes, :stdin, :stdout, :stderr
18
21
 
22
+ ##
23
+ # Prepares a `SystemCommand` object.
24
+ #
25
+ # An easy way is to use the `Builder` idea:
26
+ #
27
+ # cmd = EM::SystemCommand.new 'echo'
28
+ # cmd << :n
29
+ # cmd << 'Some text to put out.'
30
+ # cmd.execute do |on|
31
+ # on.success do
32
+ # puts 'Yay!'
33
+ # end
34
+ # end
35
+ #
19
36
  def initialize *args, &block
20
37
  @pipes = {}
21
38
  @command = EM::SystemCommand::Builder.new *args
@@ -23,12 +40,18 @@ module EventMachine
23
40
  @execution_proc = block
24
41
  end
25
42
 
43
+ ##
44
+ # Convinience method to quickly execute a command.
26
45
  def self.execute *args, &block
27
46
  sys_cmd = EM::SystemCommand.new *args, &block
28
47
  sys_cmd.execute
29
48
  end
30
49
 
31
- # Executes the command
50
+ ##
51
+ # Executes the command from the `Builder` object.
52
+ # If there had been given a block at instantiation it will be
53
+ # called after the `popen3` call and after the pipes have been
54
+ # attached.
32
55
  def execute &block
33
56
  raise 'Previous process still exists' unless pipes.empty?
34
57
 
@@ -50,10 +73,20 @@ module EventMachine
50
73
  self
51
74
  end
52
75
 
76
+ ##
77
+ # Returns the command string.
78
+ def command
79
+ @command.to_s
80
+ end
81
+
82
+ ##
83
+ # Returns the pid of the child process.
53
84
  def pid
54
85
  @wait_thr.pid
55
86
  end
56
87
 
88
+ ##
89
+ # Returns the status object of the popen3 call.
57
90
  def status
58
91
  @wait_thr.value
59
92
  end
@@ -61,6 +94,8 @@ module EventMachine
61
94
  alias_method :success, :callback
62
95
  alias_method :failure, :errback
63
96
 
97
+ ##
98
+ # Called by child pipes when they get unbound.
64
99
  def unbind name
65
100
  pipes.delete name
66
101
  if pipes.empty?
@@ -72,6 +107,8 @@ module EventMachine
72
107
  end
73
108
  end
74
109
 
110
+ ##
111
+ # Kills the child process.
75
112
  def kill signal = 'TERM', wait = false
76
113
  Process.kill signal, self.pid
77
114
  val = status if wait
@@ -80,6 +117,5 @@ module EventMachine
80
117
  @stderr.close
81
118
  val
82
119
  end
83
-
84
120
  end
85
121
  end
@@ -82,6 +82,17 @@ describe EM::SystemCommand do
82
82
  end
83
83
  end
84
84
 
85
+ it 'should proxy builder commands' do
86
+ EM.run do
87
+ cmd = EM::SystemCommand.new 'echo'
88
+ cmd << '-n'
89
+ cmd.add 'Something\n'
90
+ cmd.execute
91
+ EM.stop_event_loop
92
+ end
93
+ end
94
+
95
+
85
96
  describe 'subclass' do
86
97
  before :all do
87
98
  class DummyCmd < EM::SystemCommand;end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-systemcommand
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  segments:
149
149
  - 0
150
- hash: 1884745858443868072
150
+ hash: -2860876855106188560
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  segments:
158
158
  - 0
159
- hash: 1884745858443868072
159
+ hash: -2860876855106188560
160
160
  requirements: []
161
161
  rubyforge_project:
162
162
  rubygems_version: 1.8.24