Module: Rack::Handler::Puma

Defined in:
lib/rack/handler/puma.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :Verbose => false,
  :Silent  => false
}

Class Method Summary collapse

Class Method Details

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

Yields:

  • (launcher)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rack/handler/puma.rb', line 12

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

  conf = ::Puma::Configuration.new(options) do |c|
    c.quiet

    if options.delete(:Verbose)
      app = Rack::CommonLogger.new(app, STDOUT)
    end

    if options[:environment]
      c.environment options[:environment]
    end

    if options[:Threads]
      min, max = options.delete(:Threads).split(':', 2)
      c.threads min, max
    end

    host = options[:Host]

    if host && (host[0,1] == '.' || host[0,1] == '/')
      c.bind "unix://#{host}"
    else
      host ||= ::Puma::Configuration::DefaultTCPHost
      port = options[:Port] || ::Puma::Configuration::DefaultTCPPort

      c.port port, host
    end

    c.app app
  end

  events = options.delete(:Silent) ? ::Puma::Events.strings : ::Puma::Events.stdio

  launcher = ::Puma::Launcher.new(conf, :events => events)

  yield launcher if block_given?
  begin
    launcher.run
  rescue Interrupt
    puts "* Gracefully stopping, waiting for requests to finish"
    launcher.stop
    puts "* Goodbye!"
  end
end

.valid_optionsObject



59
60
61
62
63
64
65
66
# File 'lib/rack/handler/puma.rb', line 59

def self.valid_options
  {
    "Host=HOST"       => "Hostname to listen on (default: localhost)",
    "Port=PORT"       => "Port to listen on (default: 8080)",
    "Threads=MIN:MAX" => "min:max threads to use (default 0:16)",
    "Verbose"         => "Don't report each request (default: false)"
  }
end