Skip to content

Instantly share code, notes, and snippets.

@niw
Created October 29, 2013 03:16
Show Gist options
  • Select an option

  • Save niw/7208705 to your computer and use it in GitHub Desktop.

Select an option

Save niw/7208705 to your computer and use it in GitHub Desktop.

Revisions

  1. niw created this gist Oct 29, 2013.
    28 changes: 28 additions & 0 deletions rubygems_server.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/usr/bin/env ruby
    require 'webrick'

    require 'rubygems'
    require 'rubygems/gem_runner'
    require 'rubygems/exceptions'

    REPOSITORY_ROOT = File.expand_path("../", __FILE__)

    # Update index
    begin
    Gem::GemRunner.new.run ["generate_index", "-d", REPOSITORY_ROOT]
    rescue Gem::SystemExitException => e
    exit e.exit_code
    end

    # Start HTTP server
    WEBrick::HTTPServer.new(
    :Port => 3000,
    :BindAddress => '127.0.0.0',
    :DocumentRoot => REPOSITORY_ROOT,
    :MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes
    ).tap do |server|
    trap('INT') do
    server.shutdown
    end
    server.start
    end