Permalink
Browse files

Added bouncer method

  • Loading branch information...
1 parent 010f860 commit 6a515dd1dbe3452a198ba17979eede2519f1804b Avdi Grimm committed Jan 11, 2010
Showing with 16 additions and 13 deletions.
  1. +16 −13 lib/cowsay.rb
View
29 lib/cowsay.rb
@@ -20,15 +20,17 @@ def say(message, options={})
end
results = []
messages.each do |message|
- @io_class.popen(command, "w+") do |process|
- results << begin
- process.write(message)
- process.close_write
- result = process.read
- rescue Errno::EPIPE
- message
- end
- end
+ check_child_exit_status {
+ @io_class.popen(command, "w+") do |process|
+ results << begin
+ process.write(message)
+ process.close_write
+ result = process.read
+ rescue Errno::EPIPE
+ message
+ end
+ end
+ }
end
output = results.join("\n")
if options[:out]
@@ -40,16 +42,17 @@ def say(message, options={})
else options[:out].inspect
end
@logger.info "Wrote to #{destination}"
- check_child_exit_status!
output
end
private
- def check_child_exit_status!(status=$?)
- status ||= OpenStruct.new(:exitstatus => 0)
+ def check_child_exit_status
+ yield
+ status = $? || OpenStruct.new(:exitstatus => 0)
unless [0,172].include?(status.exitstatus)
- raise ArgumentError, "Command exited with status #{status.exitstatus}"
+ raise ArgumentError,
+ "Command exited with status #{status.exitstatus}"
end
end
end

0 comments on commit 6a515dd

Please sign in to comment.