Class: Rad::Http::RackAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rad/http/_support/rack/rack_adapter.rb

Constant Summary collapse

SERVERS =
%w{thin mongrel webrick}

Instance Method Summary collapse

Instance Method Details

#configure_rack!(builder) ⇒ Object



12
13
14
15
# File 'lib/rad/http/_support/rack/rack_adapter.rb', line 12

def configure_rack! builder
  raise "Rack stack not defined! Use profiles (see rad/profiles/web.rb), or use your own configuration!" if stack.empty?
  stack.each{|conf| conf.call builder}
end

#quit!(server, handler_name) ⇒ Object



33
34
35
36
37
# File 'lib/rad/http/_support/rack/rack_adapter.rb', line 33

def quit!(server, handler_name)
  ## Use thins' hard #stop! if available, otherwise just #stop
  server.respond_to?(:stop!) ? server.stop! : server.stop
  puts "\nRad stopped" unless handler_name =~/cgi/i
end

#run(app, host, port) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rad/http/_support/rack/rack_adapter.rb', line 21

def run app, host, port
  handler = detect_rack_handler
  handler_name = handler.name.gsub(/.*::/, '')
  logger.info "RAD http server started on #{host}:#{port}" unless rad.test?
  # unless handler_name =~/cgi/i
  handler.run app, Host: host, Port: port do |server|
    [:INT, :TERM].each {|sig| trap(sig){quit!(server, handler_name)}}
  end
rescue Errno::EADDRINUSE => e
  logger.error "RAD port #{port} taken!"
end

#stackObject



17
18
19
# File 'lib/rad/http/_support/rack/rack_adapter.rb', line 17

def stack
  @rack_stack ||= []
end