diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-15 21:10:26 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-15 21:10:26 +0000 |
commit | c46e390920950f273bdfc1c664f5e672f59e3a21 (patch) | |
tree | 3d912a2b9e530762a08260b5dc50be0eecaa39ef /railties/lib/breakpoint_client.rb | |
parent | fb13b7a495c248479f77d42a55e1c3e47c78c49c (diff) | |
download | rails-c46e390920950f273bdfc1c664f5e672f59e3a21.tar.gz rails-c46e390920950f273bdfc1c664f5e672f59e3a21.tar.bz2 rails-c46e390920950f273bdfc1c664f5e672f59e3a21.zip |
Fixed some breakpoint issues and made breakpoint_client depend on activerecord/support instead of duplicating the files in railties #441 [Florian Gross]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@424 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/breakpoint_client.rb')
-rw-r--r-- | railties/lib/breakpoint_client.rb | 119 |
1 files changed, 69 insertions, 50 deletions
diff --git a/railties/lib/breakpoint_client.rb b/railties/lib/breakpoint_client.rb index fa93c11f3e..078824fad2 100644 --- a/railties/lib/breakpoint_client.rb +++ b/railties/lib/breakpoint_client.rb @@ -57,6 +57,15 @@ ARGV.options do |opts| "Show this help message." ) { puts opts; exit } + opts.on("-v", "--version", + "Display the version information." + ) do + id = %q$Id$ + puts id.sub("Id: ", "") + puts "(Breakpoint::Version = #{Breakpoint::Version})" + exit + end + opts.parse! end @@ -68,6 +77,60 @@ trap("INT"){$running = false} puts "Waiting for initial breakpoint..." +module Handlers + extend self + + def breakpoint_handler(workspace, message) + puts message + IRB.start(nil, nil, workspace) + puts "", "Resumed execution. Waiting for next breakpoint...", "" + end + + def eval_handler(code) + result = eval(code, TOPLEVEL_BINDING) + if result then + DRbObject.new(result) + else + result + end + end + + def collision_handler() + msg = [ + " *** Breakpoint service collision ***", + " Another Breakpoint service tried to use the", + " port already occupied by this one. It will", + " keep waiting until this Breakpoint service", + " is shut down.", + " ", + " If you are using the Breakpoint library for", + " debugging a Rails or other CGI application", + " this likely means that this Breakpoint", + " session belongs to an earlier, outdated", + " request and should be shut down via 'exit'." + ].join("\n") + + if RUBY_PLATFORM["win"] then + # This sucks. Sorry, I'm not doing this because + # I like funky message boxes -- I need to do this + # because on Windows I have no way of displaying + # my notification via puts() when gets() is still + # being performed on STDIN. I have not found a + # better solution. + begin + require 'tk' + root = TkRoot.new { withdraw } + Tk.messageBox('message' => msg, 'type' => 'ok') + root.destroy + rescue Exception + puts "", msg, "" + end + else + puts "", msg, "" + end + end +end + loop do DRb.start_service(options[:ClientURI]) @@ -90,55 +153,9 @@ loop do end begin - service.register_eval_handler do |code| - result = eval(code, TOPLEVEL_BINDING) - if result - DRbObject.new(result) - else - result - end - end - - service.register_collision_handler do - msg = [ - " *** Breakpoint service collision ***", - " Another Breakpoint service tried to use the", - " port already occupied by this one. It will", - " keep waiting until this Breakpoint service", - " is shut down.", - " ", - " If you are using the Breakpoint library for", - " debugging a Rails or other CGI application", - " this likely means that this Breakpoint", - " session belongs to an earlier, outdated", - " request and should be shut down via 'exit'." - ].join("\n") - - if RUBY_PLATFORM["win"] then - # This sucks. Sorry, I'm not doing this because - # I like funky message boxes -- I need to do this - # because on Windows I have no way of displaying - # my notification via puts() when gets() is still - # being performed on STDIN. I have not found a - # better solution. - begin - require 'tk' - root = TkRoot.new { withdraw } - Tk.messageBox('message' => msg, 'type' => 'ok') - root.destroy - rescue Exception - puts "", msg, "" - end - else - puts "", msg, "" - end - end - - service.register_handler do |workspace, message| - puts message - IRB.start(nil, nil, workspace) - puts "", "Resumed execution. Waiting for next breakpoint...", "" - end + service.eval_handler = Handlers.method(:eval_handler) + service.collision_handler = Handlers.method(:collision_handler) + service.handler = Handlers.method(:breakpoint_handler) puts "Connection established. Waiting for breakpoint...", "" if options[:Verbose] @@ -153,7 +170,9 @@ loop do sleep(0.5) end ensure - service.unregister_handler + service.eval_handler = nil + service.collision_handler = nil + service.handler = nil end rescue Exception => error break unless $running |