Skip to content

Commit 211aef1

Browse files
committed
Advertise the Configuration object for apps to use.
1 parent 40af41e commit 211aef1

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

lib/puma/cli.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ def parse_options
327327
end
328328

329329
@config = Puma::Configuration.new @options
330+
331+
# Advertise the Configuration
332+
Puma.cli_config = @config
333+
330334
@config.load
331335
end
332336

lib/puma/configuration.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
module Puma
2+
3+
# The CLI exports it's Configuration object here to allow
4+
# apps to pick it up. An app needs to use it conditionally though
5+
# since it is not set if the app is launched via another
6+
# mechanism than the CLI class.
7+
8+
class << self
9+
attr_accessor :cli_config
10+
end
11+
212
class Configuration
313
DefaultRackup = "config.ru"
414

@@ -44,6 +54,19 @@ def load
4454
end
4555
end
4656

57+
# Injects the Configuration object into the env
58+
class ConfigMiddleware
59+
def initialize(config, app)
60+
@config = config
61+
@app = app
62+
end
63+
64+
def call(env)
65+
env[Const::PUMA_CONFIG] = @config
66+
@app.call(env)
67+
end
68+
end
69+
4770
# Load the specified rackup file, pull an options from
4871
# the rackup file, and set @app.
4972
#
@@ -72,7 +95,7 @@ def app
7295
app = Rack::CommonLogger.new(app, logger)
7396
end
7497

75-
return app
98+
return ConfigMiddleware.new(self, app)
7699
end
77100

78101
def setup_random_token

lib/puma/const.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ module Const
119119
RACK_URL_SCHEME = "rack.url_scheme".freeze
120120
RACK_AFTER_REPLY = "rack.after_reply".freeze
121121
PUMA_SOCKET = "puma.socket".freeze
122+
PUMA_CONFIG = "puma.config".freeze
122123

123124
HTTP = "http".freeze
124125
HTTPS = "https".freeze

0 commit comments

Comments
 (0)