From 5f24229fbc328aa13f396c0e2ac1fb508411c528 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 30 Jan 2017 20:29:19 -0800 Subject: [PATCH 1/2] Specified parameters should overwrite loaded config files --- lib/puma/configuration.rb | 8 +++++++- test/config/settings.rb | 2 ++ test/test_config.rb | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/config/settings.rb diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 850d55f6..9fcacb9a 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -30,6 +30,11 @@ module Puma @set << @cur end + def reverse_shift + @cur = {} + @set.unshift(@cur) + end + def [](key) @set.reverse_each do |o| if o.key? key @@ -201,10 +206,11 @@ module Puma end files.each do |f| - @options.shift + @options.reverse_shift DSL.load @options, self, f end + @options.shift end # Call once all configuration (included from rackup files) diff --git a/test/config/settings.rb b/test/config/settings.rb new file mode 100644 index 00000000..4c2b8f22 --- /dev/null +++ b/test/config/settings.rb @@ -0,0 +1,2 @@ +port 3000 +threads 3, 5 diff --git a/test/test_config.rb b/test/test_config.rb index 2290ebb4..752f86ac 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -67,6 +67,17 @@ class TestConfigFile < Minitest::Test assert_equal conf.options[:workers], 4 end + def test_parameters_overwrite_files + conf = Puma::Configuration.new(config_files: ['test/config/settings.rb']) do |c| + c.port 3030 + end + conf.load + + assert_match(/:3030$/, conf.options[:binds].first) + assert_equal 3, conf.options[:min_threads] + assert_equal 5, conf.options[:max_threads] + end + private def with_env(env = {}) From e127249c2a32c514c9a2cebc7d715dfceb722959 Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Thu, 9 Feb 2017 07:31:49 -0700 Subject: [PATCH 2/2] Revert "Revert "fix access priorities of each level in LeveledOptions"" This reverts commit 30c12cad08c22a40f89201882ec19f9ca587339d. --- lib/puma/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 84b0a8ea..9fcacb9a 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -36,7 +36,7 @@ module Puma end def [](key) - @set.each do |o| + @set.reverse_each do |o| if o.key? key return o[key] end