Sha256: 8c52dfce6be1055790261e156e7e44501c3f2335f11a992edda287dad7d89908

Contents?: true

Size: 693 Bytes

Versions: 1

Compression:

Stored size: 693 Bytes

Contents

require 'json'

module TestR
module Server

  def quit
    throw :testr_server_quit
  end

  def loop
    (@upstream = STDOUT.dup).sync = true
    STDOUT.reopen(STDERR).sync = true

    catch :testr_server_quit do
      while line = STDIN.gets
        warn "#{caller[2]} RECV #{line.chomp}" if $DEBUG

        command = JSON.load(line)
        method = command.first

        if respond_to? method and method != __method__ # prevent loops
          @command, @command_line = command, line
          __send__(*command)
        else
          warn "#{self}: bad command: #{method}"
        end
      end
    end
  end

  def self.extended target
    trap(:SIGTERM){ target.quit }
  end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
testr-14.1.0 lib/testr/server.rb