Class: Rack::Handler::Startbrick

Inherits:
WEBrick
  • Object
show all
Defined in:
lib/startbrick.rb

Class Method Summary collapse

Class Method Details

.run(app, options = {}) {|@server| ... } ⇒ Object

Yields:

  • (@server)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/startbrick.rb', line 9

def self.run(app, options={})

  options[:BindAddress] = options.delete(:Host) if options[:Host]

  options[:StartCallback] = if ::File.size?(SCRIPT_FILE)
    script = ::File.read(SCRIPT_FILE)
    puts "Loading #{SCRIPT_FILE} script:\n\n#{script.gsub(/^/, '  ')}"
    Proc.new {
      puts "Executing #{SCRIPT_FILE}"
      fork { `bash #{SCRIPT_FILE}` }
    }
  else
    Proc.new {
      url = "http://#{options[:BindAddress]}:#{options[:Port]}"
      cmd = "open #{url}"
      puts "Running '#{cmd}'"
      fork { `#{cmd}` }
    }
    
  end
  @server = ::WEBrick::HTTPServer.new(options)
  @server.mount "/", Rack::Handler::WEBrick, app
  yield @server  if block_given?
  @server.start
end