File tree Expand file tree Collapse file tree 5 files changed +74
-0
lines changed Expand file tree Collapse file tree 5 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 5
5
gem "rails" , ">= 7.0.1"
6
6
gem "rake"
7
7
gem "debug"
8
+ gem "puma"
Original file line number Diff line number Diff line change 134
134
racc (~> 1.4 )
135
135
psych (5.1.2 )
136
136
stringio
137
+ puma (6.4.2 )
138
+ nio4r (~> 2.0 )
137
139
racc (1.8.1 )
138
140
rack (3.1.7 )
139
141
rack-session (2.0.0 )
@@ -199,6 +201,7 @@ PLATFORMS
199
201
DEPENDENCIES
200
202
debug
201
203
propshaft !
204
+ puma
202
205
rails (>= 7.0.1 )
203
206
rake
204
207
Original file line number Diff line number Diff line change
1
+ begin
2
+ require "puma"
3
+ require "puma/configuration"
4
+ rescue LoadError
5
+ end
6
+
7
+ class Propshaft ::PumaConfig
8
+ def initialize
9
+ if defined? ( Puma )
10
+ @resolved_config = Puma ::Configuration . new . load . final_options
11
+ end
12
+ end
13
+
14
+ def multiple_workers?
15
+ return false unless @resolved_config
16
+ @resolved_config [ :workers ] > 1
17
+ end
18
+
19
+ def self . perform_dev_check!
20
+ return true unless new . multiple_workers?
21
+
22
+ message = "#" * 80 + "\n "
23
+ message += "# " + " " * 76 + " #\n "
24
+ message += "# " + "WARNING!!" . center ( 76 ) + " #\n "
25
+ message += "# " + " " * 76 + " #\n "
26
+ message += "# Running multiple Puma workers in development is not supported with Propshaft #\n "
27
+ message += "# " + " " * 76 + " #\n "
28
+ message += "# " + "Make sure WEB_CONCURRENCY is not set or ensure" . center ( 76 ) + " #\n "
29
+ message += "# " + "workers is not set for development in config/puma.rb." . center ( 76 ) + " #\n "
30
+ message += "# " + " " * 76 + " #\n "
31
+ message += "#" * 80 + "\n "
32
+
33
+ puts message
34
+ false
35
+ end
36
+ end
Original file line number Diff line number Diff line change 2
2
require "active_support/ordered_options"
3
3
require "propshaft"
4
4
require "propshaft/quiet_assets"
5
+ require "propshaft/puma_config"
5
6
6
7
module Propshaft
7
8
class Railtie < ::Rails ::Railtie
@@ -43,6 +44,10 @@ class Railtie < ::Rails::Railtie
43
44
app . routes . prepend do
44
45
mount app . assets . server , at : app . assets . config . prefix
45
46
end
47
+
48
+ if Rails . env . development?
49
+ exit 1 unless PumaConfig . perform_dev_check!
50
+ end
46
51
end
47
52
48
53
ActiveSupport . on_load ( :action_view ) do
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+ require "puma"
3
+ require "propshaft/puma_config"
4
+ require "minitest/mock"
5
+
6
+ class Propshaft ::PumaConfigTest < ActiveSupport ::TestCase
7
+ class PumaConfigurationStub
8
+ def initialize ( workers )
9
+ @workers = workers
10
+ end
11
+
12
+ def load
13
+ OpenStruct . new ( final_options : { workers : @workers } )
14
+ end
15
+ end
16
+
17
+ {
18
+ 0 => false ,
19
+ 1 => false ,
20
+ 2 => true
21
+ } . each_pair do |workers , expected |
22
+ test "multiple_workers? is #{ expected } when config resolves to #{ workers } " do
23
+ mock = PumaConfigurationStub . new ( workers )
24
+ Puma ::Configuration . stub :new , mock do
25
+ assert Propshaft ::PumaConfig . new . multiple_workers? == expected
26
+ end
27
+ end
28
+ end
29
+ end
You can’t perform that action at this time.
0 commit comments