Sha256: f10670f40197bb1a044b0d4d40b8d3ee92b449ac095def48a04073a7af6fd909

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

class Rad::Http::RackAdapter
  SERVERS = %w{thin mongrel webrick}

  # class Callback
  #   def initialize app; end
  #   def self.call env; Rad::Adapter.call env end
  # end

  # class << self
  inject logger: :logger
  
  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
  
  def stack
    @rack_stack ||= []
  end

  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

  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

  protected        
    def detect_rack_handler
      return Rack::Handler.get('thin')
      SERVERS.each do |server_name|
        begin
          return Rack::Handler.get(server_name.downcase)
        rescue LoadError
        rescue NameError
        end
      end
      fail "  Server handler (#{SERVERS.join(', ')}) not found."
    end
    
  # end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rad_core-0.2.6 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.2.5 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.2.4 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.2.3 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.2.2 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.2.1 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.2.0 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.0.30 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.0.29 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.0.28 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.0.27 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.0.26 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.0.25 lib/rad/http/_support/rack/rack_adapter.rb
rad_core-0.0.24 lib/rad/http/_support/rack/rack_adapter.rb