Class: Guard::Yard::Server

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

Overview

Responsible for running, verifying and killing the YARD server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



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

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

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#pidObject

Returns the value of attribute pid.



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

def pid
  @pid
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#killObject



28
29
30
31
32
# File 'lib/guard/yard/server.rb', line 28

def kill
  UI.info '[Guard::Yard] Stopping YARD Documentation Server.'
  return true unless pid
  Gem.win_platform? ? windows_kill : posix_kill
end

#spawnObject



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

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

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

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

#verifyObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/guard/yard/server.rb', line 34

def verify
  5.times do
    sleep 1
    begin
      TCPSocket.new(host, 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