Sha256: cfcffa595d18ed553922a9055e39c5a367bba4dafc3033bd1b7bba1891409d41

Contents?: true

Size: 639 Bytes

Versions: 2

Compression:

Stored size: 639 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'webrick'

module Genit

  # I use WEBrick to serve the html from the root directory.
  class Server

    # Public: Constructor.
    #
    # wd - The String working directory, where live the project.
    def initialize wd
      @server = WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => wd)
      ['INT', 'TERM'].each {|signal| trap_this signal }
    end

    # Start the web server.
    #
    # Returns nothing.
    def start
      puts "Press Ctrl-C to close."
      @server.start
    end

    private

      def trap_this signal
         trap(signal) { @server.shutdown } 
      end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
genit-2.1 lib/genit/server/server.rb
genit-2.0 lib/genit/server/server.rb