Class: Webby::AutoBuilder::WebServer

Inherits:
Object
  • Object
show all
Defined in:
lib/webby/auto_builder.rb

Overview

Wrapper class around the webrick web server.

Instance Method Summary collapse

Constructor Details

#initializeWebServer

Create a new webrick server configured to serve pages from the output directory. Output will be directed to /dev/null.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/webby/auto_builder.rb', line 106

def initialize
  logger = WEBrick::Log.new(Kernel::DEV_NULL, WEBrick::Log::DEBUG)
  access_log = [[ logger, WEBrick::AccessLog::COMBINED_LOG_FORMAT ]]

  @thread = nil
  @running = false
  @server = WEBrick::HTTPServer.new(
    :BindAddress   => 'localhost',
    :Port          => ::Webby.site.web_port,
    :DocumentRoot  => ::Webby.site.output_dir,
    :FancyIndexing => true,
    :Logger        => logger,
    :AccessLog     => access_log
  )
end

Instance Method Details

#joinObject

Join on the webserver thread.



147
148
149
150
# File 'lib/webby/auto_builder.rb', line 147

def join
  return if not running?
  @thread.join
end

#running?Boolean

Returns true if the server is running.



124
125
126
# File 'lib/webby/auto_builder.rb', line 124

def running?
  @running
end

#startObject

Start the webrick server running in a separate thread (so we don't block forever).



131
132
133
134
135
# File 'lib/webby/auto_builder.rb', line 131

def start
  return if running?
  @running = true
  @thread = Thread.new {@server.start}
end

#stopObject

Stop the webrick server.



139
140
141
142
143
# File 'lib/webby/auto_builder.rb', line 139

def stop
  return if not running?
  @running = false
  @server.shutdown
end