Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding options of Configuration object #936

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/puma/configuration.rb
Expand Up @@ -13,10 +13,10 @@ module ConfigDefault
end

class LeveledOptions
def initialize(default={})
@cur = {}
def initialize(default_options, user_options)
@cur = user_options
@set = [@cur]
@defaults = default.dup
@defaults = default_options.dup
end

def initialize_copy(other)
Expand Down Expand Up @@ -133,12 +133,9 @@ def self.from_file(path)
end

def initialize(options={}, &blk)
@options = LeveledOptions.new(default_options)
@plugins = PluginLoader.new
@options = LeveledOptions.new(default_options, options)

# options.each do |k,v|
# @options[k] = v
# end
@plugins = PluginLoader.new

if blk
configure(&blk)
Expand Down
3 changes: 1 addition & 2 deletions lib/rack/handler/puma.rb
Expand Up @@ -12,7 +12,7 @@ module Puma
def self.run(app, options = {})
options = DEFAULT_OPTIONS.merge(options)

conf = ::Puma::Configuration.new do |c|
conf = ::Puma::Configuration.new(options) do |c|
c.quiet

if options.delete(:Verbose)
Expand Down Expand Up @@ -69,4 +69,3 @@ def self.valid_options
register :puma, Puma
end
end

6 changes: 6 additions & 0 deletions test/test_config.rb
Expand Up @@ -51,6 +51,12 @@ def test_lowleve_error_handler_DSL
assert_equal [200, {}, ["error page"]], app.call({})
end

def test_allow_users_to_override_default_options
conf = Puma::Configuration.new(restart_cmd: 'bin/rails server')

assert_equal 'bin/rails server', conf.options[:restart_cmd]
end

private

def with_env(env = {})
Expand Down