Class Webby::AutoBuilder::WebServer
In: lib/webby/auto_builder.rb
Parent: Object

Wrapper class around the webrick web server.

Methods

join   new   running?   start   stop  

Public Class methods

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

[Source]

# 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

Public Instance methods

Join on the webserver thread.

[Source]

# File lib/webby/auto_builder.rb, line 147
    def join
      return if not running?
      @thread.join
    end

Returns true if the server is running.

[Source]

# File lib/webby/auto_builder.rb, line 124
    def running?
      @running
    end

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

[Source]

# File lib/webby/auto_builder.rb, line 131
    def start
      return if running?
      @running = true
      @thread = Thread.new {@server.start}
    end

Stop the webrick server.

[Source]

# File lib/webby/auto_builder.rb, line 139
    def stop
      return if not running?
      @running = false
      @server.shutdown
    end

[Validate]