Skip to content

Commit c80fe10

Browse files
committed
Move debugger into middleware
1 parent 07abc5e commit c80fe10

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

railties/lib/commands/server.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,11 @@
8383
app = Rack::Builder.new {
8484
use Rails::Rack::Logger
8585
use Rails::Rack::Static
86+
use Rails::Rack::Debugger if options[:debugger]
8687
run ActionController::Dispatcher.new
8788
}.to_app
8889
end
8990

90-
if options[:debugger]
91-
begin
92-
require_library_or_gem 'ruby-debug'
93-
Debugger.start
94-
Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
95-
puts "=> Debugger enabled"
96-
rescue Exception
97-
puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
98-
exit
99-
end
100-
end
101-
10291
puts "=> Call with -d to detach"
10392

10493
trap(:INT) { exit }

railties/lib/rails/rack.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Rails
22
module Rack
3+
autoload :Debugger, "rails/rack/debugger"
34
autoload :Logger, "rails/rack/logger"
45
autoload :Static, "rails/rack/static"
56
end

railties/lib/rails/rack/debugger.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Rails
2+
module Rack
3+
class Debugger
4+
def initialize(app)
5+
@app = app
6+
7+
require_library_or_gem 'ruby-debug'
8+
::Debugger.start
9+
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
10+
puts "=> Debugger enabled"
11+
rescue Exception
12+
puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
13+
exit
14+
end
15+
16+
def call(env)
17+
@app.call(env)
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)