Skip to content
Browse files

Block no longer required

  • Loading branch information...
1 parent f9000ff commit 507d23c10ef9b7ea7cc8a9dcb861af4c6bcb8ec7 twinturbo committed Aug 8, 2012
Showing with 10 additions and 31 deletions.
  1. +9 −28 lib/iridium/command_streamer.rb
  2. +1 −3 test/command_streamer_test.rb
View
37 lib/iridium/command_streamer.rb
@@ -1,46 +1,27 @@
require 'pty'
require 'json'
-
module Iridium
class CommandStreamer
class CommandFailed < RuntimeError ; end
class ProcessAborted < RuntimeError ; end
- # PTY IO is platform dependent on. Reading raises a Errno:EIO
- # as regular behavior on some platforms. Wrap it up here so
- # things behave like developers expect
- class SafePTY
- def self.spawn(command, &block)
- PTY.spawn(command) do |r,w,p|
- begin
- yield r,w,p
- rescue Errno::EIO
- end
- end
-
- $?.exitstatus
- end
- end
-
def initialize(command)
@command = command
end
def run(options = {})
- SafePTY.spawn @command do |stdin, stdout, pid|
+ PTY.spawn @command do |stdin, stdout, pid|
stdin.each do |output|
begin
- if block_given?
- json = JSON.parse output
-
- if json.is_a?(Hash) && json['iridium']
- yield json['iridium']
- elsif json.is_a?(Hash) && json['abort']
- raise ProcessAborted, json['abort']
- else
- puts output if options[:debug]
- end
+ json = JSON.parse output
+
+ if json.is_a?(Hash) && json['iridium']
+ yield json['iridium'] if block_given?
+ elsif json.is_a?(Hash) && json['abort']
+ raise ProcessAborted, json['abort']
+ else
+ puts output if options[:debug]
end
rescue JSON::ParserError
puts output if options[:debug]
View
4 test/command_streamer_test.rb
@@ -46,9 +46,7 @@ def test_raises_an_error_when_process_sends_an_abort_signal
command = Iridium::CommandStreamer.new "echo #{Shellwords.shellescape(json)}"
assert_raises Iridium::CommandStreamer::ProcessAborted do
- command.run do
- # do nothing, block required to accept messages
- end
+ command.run
end
end
end

0 comments on commit 507d23c

Please sign in to comment.
Something went wrong with that request. Please try again.