Class: Guard::Yard::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/yard/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



8
9
10
11
12
13
# File 'lib/guard/yard/server.rb', line 8

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

Instance Attribute Details

#pidObject

Returns the value of attribute pid.



6
7
8
# File 'lib/guard/yard/server.rb', line 6

def pid
  @pid
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/guard/yard/server.rb', line 6

def port
  @port
end

Instance Method Details

#killObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/guard/yard/server.rb', line 26

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

#spawnObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/guard/yard/server.rb', line 15

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

#verifyObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/guard/yard/server.rb', line 39

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