Class: Guard::Yard::Server
- Inherits:
-
Object
- Object
- Guard::Yard::Server
- Defined in:
- lib/guard/yard/server.rb
Overview
Responsible for running, verifying and killing the YARD server.
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #kill ⇒ Object
- #spawn ⇒ Object
- #verify ⇒ Object
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( = {}) @port = [:port] || '8808' @host = [:host] || 'localhost' @stdout = [:stdout] @stderr = [:stderr] @cli = [:cli] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/guard/yard/server.rb', line 7 def host @host end |
#pid ⇒ Object
Returns the value of attribute pid.
7 8 9 |
# File 'lib/guard/yard/server.rb', line 7 def pid @pid end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/guard/yard/server.rb', line 7 def port @port end |
Instance Method Details
#kill ⇒ Object
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 |
#spawn ⇒ Object
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 |
#verify ⇒ Object
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 |