class RDoc::Server
A minimal HTTP server for live-reloading RDoc documentation.
Uses Ruby’s built-in TCPServer (no external dependencies).
Used by rdoc --server to let developers preview documentation while editing source files. Parses sources once on startup, watches for file changes, re-parses only the changed files, and auto-refreshes the browser via a simple polling script.
Constants
- CONTENT_TYPES
- LIVE_RELOAD_SCRIPT
- STATUS_TEXTS
Public Class Methods
Source
# File lib/rdoc/server.rb, line 56 def initialize(rdoc, port) @rdoc = rdoc @options = rdoc.options @store = rdoc.store @port = port @generator = create_generator @page_cache = {} @search_index_cache = nil @last_change_time = Time.now.to_f @mutex = Mutex.new @running = false end
Creates a new server.
rdoc is the RDoc::RDoc instance that has already parsed the source files. port is the TCP port to listen on.
Public Instance Methods
Source
# File lib/rdoc/server.rb, line 94 def shutdown @running = false @tcp_server&.close @watcher_thread&.join(2) end
Shuts down the server.
Source
# File lib/rdoc/server.rb, line 73 def start @tcp_server = TCPServer.new('127.0.0.1', @port) @running = true @watcher_thread = start_watcher(@rdoc.last_modified.keys) url = "http://localhost:#{@port}" $stderr.puts "\nServing documentation at: \e]8;;#{url}\e\\#{url}\e]8;;\e\\" $stderr.puts "Press Ctrl+C to stop.\n\n" loop do client = @tcp_server.accept Thread.new(client) { |c| handle_client(c) } rescue IOError break end end
Starts the server. Blocks until interrupted.