Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Advertise the Configuration object for apps to use.
  • Loading branch information
evanphx committed Feb 6, 2013
1 parent 40af41e commit 211aef1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/puma/cli.rb
Expand Up @@ -327,6 +327,10 @@ def parse_options
end

@config = Puma::Configuration.new @options

# Advertise the Configuration
Puma.cli_config = @config

@config.load
end

Expand Down
25 changes: 24 additions & 1 deletion lib/puma/configuration.rb
@@ -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"

Expand Down Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/puma/const.rb
Expand Up @@ -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
Expand Down

0 comments on commit 211aef1

Please sign in to comment.