Sha256: 7b8b3aebe891dfce53babf7fc9879510d87d25bdc825e07b66f3c26b4c20dfd9

Contents?: true

Size: 654 Bytes

Versions: 4

Compression:

Stored size: 654 Bytes

Contents

module JCukeForker
  class StatusServer
    include Observable
    include Celluloid::IO

    finalizer :shutdown

    def initialize(port = '6333')
      @server = TCPServer.new 'localhost', port
    end

    def run
      loop { async.handle_connection @server.accept }
    end

    def shutdown
      @server.close if @server
    end

    def handle_connection(socket)
      until socket.eof? do
        raw_message = socket.gets
        json_obj = JSON.parse raw_message
        fire json_obj.first, *json_obj[1..-1]
      end
      socket.close
    end

    private

    def fire(*args)
      changed
      notify_observers *args
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jcukeforker-0.2.5 lib/jcukeforker/status_server.rb
jcukeforker-0.2.4 lib/jcukeforker/status_server.rb
jcukeforker-0.2.3 lib/jcukeforker/status_server.rb
jcukeforker-0.2.2 lib/jcukeforker/status_server.rb