Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Advertise the Configuration object for apps to use.
- Loading branch information
Showing
with
29 additions
and
1 deletion.
-
+4
−0
lib/puma/cli.rb
-
+24
−1
lib/puma/configuration.rb
-
+1
−0
lib/puma/const.rb
|
@@ -327,6 +327,10 @@ def parse_options |
|
|
end |
|
|
|
|
|
@config = Puma::Configuration.new @options |
|
|
|
|
|
# Advertise the Configuration |
|
|
Puma.cli_config = @config |
|
|
|
|
|
@config.load |
|
|
end |
|
|
|
|
|
|
|
@@ -1,4 +1,14 @@ |
|
|
module Puma |
|
|
|
|
|
# The CLI exports it's Configuration object here to allow |
|
|
# apps to pick it up. An app needs to use it conditionally though |
|
|
# since it is not set if the app is launched via another |
|
|
# mechanism than the CLI class. |
|
|
|
|
|
class << self |
|
|
attr_accessor :cli_config |
|
|
end |
|
|
|
|
|
class Configuration |
|
|
DefaultRackup = "config.ru" |
|
|
|
|
@@ -44,6 +54,19 @@ def load |
|
|
end |
|
|
end |
|
|
|
|
|
# Injects the Configuration object into the env |
|
|
class ConfigMiddleware |
|
|
def initialize(config, app) |
|
|
@config = config |
|
|
@app = app |
|
|
end |
|
|
|
|
|
def call(env) |
|
|
env[Const::PUMA_CONFIG] = @config |
|
|
@app.call(env) |
|
|
end |
|
|
end |
|
|
|
|
|
# Load the specified rackup file, pull an options from |
|
|
# the rackup file, and set @app. |
|
|
# |
|
@@ -72,7 +95,7 @@ def app |
|
|
app = Rack::CommonLogger.new(app, logger) |
|
|
end |
|
|
|
|
|
return app |
|
|
return ConfigMiddleware.new(self, app) |
|
|
end |
|
|
|
|
|
def setup_random_token |
|
|
|
@@ -119,6 +119,7 @@ module Const |
|
|
RACK_URL_SCHEME = "rack.url_scheme".freeze |
|
|
RACK_AFTER_REPLY = "rack.after_reply".freeze |
|
|
PUMA_SOCKET = "puma.socket".freeze |
|
|
PUMA_CONFIG = "puma.config".freeze |
|
|
|
|
|
HTTP = "http".freeze |
|
|
HTTPS = "https".freeze |
|
|