Skip to content

Commit

Permalink
Fix backwards compatibility issue.
Browse files Browse the repository at this point in the history
Environment could be a String or Proc
  • Loading branch information
ViliusLuneckas committed Jun 19, 2017
1 parent bc1ba97 commit fb3fc01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/puma/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def config_files
return [] if files == ['-']
return files if files.any?

first_default_file = %W(config/puma/#{@options[:environment].call}.rb config/puma.rb).find do |f|
first_default_file = %W(config/puma/#{environment_str}.rb config/puma.rb).find do |f|
File.exist?(f)
end

Expand Down Expand Up @@ -264,6 +264,10 @@ def environment
@options[:environment]
end

def environment_str
environment.respond_to?(:call) ? environment.call : environment
end

def load_plugin(name)
@plugins.create name
end
Expand Down
9 changes: 9 additions & 0 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def test_config_files_with_rack_env
end
end

def test_config_files_with_specified_environment
conf = Puma::Configuration.new do
end

conf.options[:environment] = 'fake-env'

assert_equal ['config/puma/fake-env.rb'], conf.config_files
end

def teardown
FileUtils.rm_r("config/puma")
end
Expand Down

0 comments on commit fb3fc01

Please sign in to comment.