Parent

Puma::Configuration

Attributes

options[R]

Public Class Methods

new(options) click to toggle source
# File lib/puma/configuration.rb, line 19
def initialize(options)
  @options = options
  @options[:mode] ||= :http
  @options[:binds] ||= []
  @options[:on_restart] ||= []
  @options[:before_worker_boot] ||= []
  @options[:after_worker_boot] ||= []
  @options[:worker_timeout] ||= DefaultWorkerTimeout
end
temp_path() click to toggle source
# File lib/puma/configuration.rb, line 149
def self.temp_path
  require 'tmpdir'

  t = (Time.now.to_f * 1000).to_i
  "#{Dir.tmpdir}/puma-status-#{t}-#{$$}"
end

Public Instance Methods

app() click to toggle source

Load the specified rackup file, pull an options from the rackup file, and set @app.

# File lib/puma/configuration.rb, line 88
def app
  app = @options[:app]

  unless app
    unless File.exist?(rackup)
      raise "Missing rackup file '#{rackup}'"
    end

    app, options = Rack::Builder.parse_file rackup
    @options.merge! options

    options.each do |key,val|
      if key.to_s[0,4] == "bind"
        @options[:binds] << val
      end
    end
  end

  if @options[:mode] == :tcp
    require 'puma/tcp_logger'

    logger = @options[:logger] || STDOUT
    return TCPLogger.new(logger, app, @options[:quiet])
  end

  if !@options[:quiet] and @options[:environment] == "development"
    logger = @options[:logger] || STDOUT
    app = Rack::CommonLogger.new(app, logger)
  end

  return ConfigMiddleware.new(self, app)
end
app_configured?() click to toggle source

Indicate if there is a properly configured app

# File lib/puma/configuration.rb, line 77
def app_configured?
  @options[:app] || File.exist?(rackup)
end
initialize_copy(other) click to toggle source
# File lib/puma/configuration.rb, line 31
def initialize_copy(other)
  @options = @options.dup
end
load() click to toggle source
# File lib/puma/configuration.rb, line 35
def load
  if path = @options[:config_file]
    DSL.new(@options)._load_from path
  end

  # Rakeup default option support
  if host = @options[:Host]
    port = @options[:Port] || DefaultTCPPort

    @options[:binds] << "tcp://#{host}:#{port}"
  end

  if @options[:binds].empty?
    @options[:binds] << "tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"
  end

  if @options[:control_url] == "auto"
    path = Configuration.temp_path
    @options[:control_url] = "unix://#{path}"
    @options[:control_url_temp] = path
  end

  unless @options[:control_auth_token]
    setup_random_token
  end
end
rackup() click to toggle source
# File lib/puma/configuration.rb, line 81
def rackup
  @options[:rackup] || DefaultRackup
end
setup_random_token() click to toggle source
# File lib/puma/configuration.rb, line 121
def setup_random_token
  begin
    require 'openssl'
  rescue LoadError
  end

  count = 16

  bytes = nil

  if defined? OpenSSL::Random
    bytes = OpenSSL::Random.random_bytes(count)
  elsif File.exist?("/dev/urandom")
    File.open("/dev/urandom") do |f|
      bytes = f.read(count)
    end
  end

  if bytes
    token = ""
    bytes.each_byte { |b| token << b.to_s(16) }
  else
    token = (0..count).to_a.map { rand(255).to_s(16) }.join
  end

  @options[:control_auth_token] = token
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.