Sha256: a140a9c9d23af5738a7a35b31e700d1d89a718ad61644da229c135fea3c6c84c

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'socket'

module Guard
  class Yard
    class Server
      attr_accessor :pid, :port

      def initialize(options = {})
        @port = options[:port] || '8808'
        @stdout = options[:stdout]
        @stderr = options[:stderr]
        @cli = options[:cli]
      end

      def spawn
        UI.info "[Guard::Yard] Starting YARD Documentation Server."

        command = ["yard server -p #{port}"]
        command << @cli if @cli
        command << "2> #{@stderr}" if @stderr
        command << "1> #{@stdout}" if @stdout

        self.pid = Process.spawn(command.join(' '))
      end

      def kill
        UI.info "[Guard::Yard] Stopping YARD Documentation Server."
        begin
          Process.kill('QUIT', pid) if pid
          Process.wait2
        rescue Errno::ESRCH, Errno::ECHILD
          # Process is already dead.
        end
        true
      end

      def verify
        5.times do
          sleep 1
          begin
            TCPSocket.new('localhost', port.to_i).close
          rescue Errno::ECONNREFUSED
            next
          end
          UI.info "[Guard::Yard] Server successfully started."
          return true
        end
        UI.error "[Guard::Yard] Error starting documentation server."
        Notifier.notify "[Guard::Yard] Server NOT started.",
          :title => 'yard', :image => :failed
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-yard-2.1.1 lib/guard/yard/server.rb