Sha256: 821ec7332926d20ce4bd1fbaa9b6ee342e47654b4526b6e6065102901653d784

Contents?: true

Size: 1021 Bytes

Versions: 9

Compression:

Stored size: 1021 Bytes

Contents

require "socket"

module CukeForker
  class VncServer

    class Error < StandardError
    end

    class << self
      def displays
        Dir[File.expand_path("~/.vnc/*.pid")].map { |e| e[/(\d+)\.pid/, 1] }.compact
      end

      def all
        displays.map { |display| new ":#{display}" }
      end
    end

    attr_reader :display

    def initialize(display = nil)
      @display = display
    end

    def start
      if display
        server display
      else
        output = server
        @display = output[/desktop is #{host}(\S+)/, 1]
      end
    end

    def stop
      server "-kill", display.to_s
    end

    private

    def server(*args)
      cmd = ['tightvncserver', args, '2>&1'].flatten.compact
      out = `#{cmd.join ' '}`

      unless last_status.success?
        raise Error, "could not run tightvncserver: #{out.inspect}"
      end

      out
    end

    def last_status
      $?
    end

    def host
      @host ||= Socket.gethostname
    end
  end # VncServer
end # CukeForker



Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cukeforker-0.0.9 lib/cukeforker/vnc_server.rb
cukeforker-0.0.8 lib/cukeforker/vnc_server.rb
cukeforker-0.0.7 lib/cukeforker/vnc_server.rb
cukeforker-0.0.6 lib/cukeforker/vnc_server.rb
cukeforker-0.0.5 lib/cukeforker/vnc_server.rb
cukeforker-0.0.4 lib/cukeforker/vnc_server.rb
cukeforker-0.0.3 lib/cukeforker/vnc_server.rb
cukeforker-0.0.2 lib/cukeforker/vnc_server.rb
cukeforker-0.0.1 lib/cukeforker/vnc_server.rb