Permalink
Browse files

Advertise the Configuration object for apps to use.

  • Loading branch information...
evanphx committed Feb 6, 2013
1 parent 40af41e commit 211aef15899a8e5b21174e74519193ead07768c9
Showing with 29 additions and 1 deletion.
  1. +4 −0 lib/puma/cli.rb
  2. +24 −1 lib/puma/configuration.rb
  3. +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

0 comments on commit 211aef1

Please sign in to comment.