Sha256: f6621ff24b2b056714296d66da0ec2e086803e7c716b0a119d58c262810a4048

Contents?: true

Size: 812 Bytes

Versions: 1

Compression:

Stored size: 812 Bytes

Contents

require 'unicorn'
require 'rack/handler'

class Rack::Handler::Unicorn
  def self.server_class
    ::Unicorn::HttpServer
  end

  def self.run app, opts
    server_name = name[/::(\w+)$/, 1].downcase
    config_path = "#{config_dir(opts)}/config/#{server_name}.rb"
    config_file = config_path if File.exist?(config_path)

    server = initialize_server(app, opts, config_file)

    yield(server) if block_given?

    server.start.join
  end

  def self.config_dir opts
    if opts[:config]
      File.dirname(opts[:config])
    else
      '.'
    end
  end

  def self.initialize_server app, opts, config_file
    server_class.new(app, :listeners   => "#{opts[:Host]}:#{opts[:Port]}",
                          :config_file => config_file)
  end
end

Rack::Handler.register('unicorn', Rack::Handler::Unicorn)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-handlers-0.7.3 lib/rack/handler/unicorn.rb