Permalink
Browse files

Update pry-remote support for pry-remote 0.1.1. #10

  • Loading branch information...
1 parent d3d92b3 commit 4e81c505a677c0f7bcd33514091c94d3ccaaab56 @nixme committed Mar 16, 2012
Showing with 36 additions and 83 deletions.
  1. +2 −0 CHANGELOG.md
  2. +3 −2 README.md
  3. +3 −0 lib/pry-nav.rb
  4. +24 −80 lib/pry-nav/pry_remote_ext.rb
  5. +3 −1 lib/pry-nav/tracer.rb
  6. +1 −0 pry-nav.gemspec
View
@@ -2,6 +2,8 @@
# Removed single letter aliases for **step**, **next**, and **continue** because
of conflicts with common variable names.
+* Update [pry-remote][pry-remote] support for 0.1.1. Older releases of
+ pry-remote no longer supported.
## 0.1.0 (2012-02-02)
View
@@ -17,8 +17,9 @@ end
**pry-nav** is not yet thread-safe, so only use in single-threaded environments.
-Rudimentary support for [pry-remote][pry-remote] is also included. Ensure
-pry-remote is loaded or required before pry-nav. For example, in a Gemfile:
+Rudimentary support for [pry-remote][pry-remote] (>= 0.1.1) is also included.
+Ensure pry-remote is loaded or required before pry-nav. For example, in a
+Gemfile:
```ruby
gem 'pry'
View
@@ -17,4 +17,7 @@ def check_file_context(target)
file = target.eval('__FILE__')
file == Pry.eval_path || (file !~ /(\(.*\))|<.*>/ && file != '' && file != '-e')
end
+
+ # Reference to currently running pry-remote server. Used by the tracer.
+ attr_accessor :current_remote_server
end
@@ -1,89 +1,31 @@
require 'pry-remote'
-require 'drb'
module PryRemote
-
- # Extraction of Object#remote_pry from
- # https://github.com/Mon-Ouie/pry-remote/blob/master/lib/pry-remote.rb
- # into separate `start` and `stop` methods so that a DRb session can last over
- # multiple Pry.start calls.
- module Server
- extend self
-
- def start(host, port)
- uri = "druby://#{host}:#{port}"
-
- @client = PryRemote::Client.new
- @started = true
- DRb.start_service uri, @client
-
- puts "[pry-remote] Waiting for client on #{uri}"
- @client.wait
-
- # If client passed stdout and stderr, redirect actual messages there.
- @old_stdout, $stdout =
- if @client.stdout
- [$stdout, @client.stdout]
- else
- [$stdout, $stdout]
- end
-
- @old_stderr, $stderr =
- if @client.stderr
- [$stderr, @client.stderr]
- else
- [$stderr, $stderr]
- end
-
- # Before Pry starts, save the pager config.
- # We want to disable this because the pager won't do anything useful in
- # this case (it will run on the server).
- Pry.config.pager, @old_pager = false, Pry.config.pager
-
- # As above, but for system config
- Pry.config.system, @old_system = PryRemote::System, Pry.config.system
-
- @client
- end
-
- def stop
- return unless @started
-
- # Reset output streams
- $stdout = @old_stdout
- $stderr = @old_stderr
-
- # Reset config
- Pry.config.pager = @old_pager
-
- # Reset system
- Pry.config.system = @old_system
-
- begin
- @client.kill
- rescue DRb::DRbConnError
- # Ignore connection errors. The CLI client may have killed itself.
- ensure
- DRb.stop_service
+ class Server
+ # Override the call to Pry.start to save off current Server, pass a
+ # pry_remote flag so pry-nav knows this is a remote session, and not kill
+ # the server right away
+ def run
+ if PryNav.current_remote_server
+ raise 'Already running a pry-remote session!'
+ else
+ PryNav.current_remote_server = self
end
- @started = false
- puts "[pry-remote] Remote sesion terminated"
+ setup
+ Pry.start @object, {
+ :input => client.input_proxy,
+ :output => client.output,
+ :pry_remote => true
+ }
end
- end
-end
-class Object
- # Override pry-remote's Object#remote_pry to use the above
- # PryRemote::Server. The PryNav::Tracer instance is responsible for
- # terminating the DRb server by calling PryRemote::Server#stop
- def remote_pry(host = 'localhost', port = 9876)
- client = PryRemote::Server.start(host, port)
- Pry.start self, {
- :input => client.input_proxy,
- :output => client.output,
- :pry_remote => true
- }
+ # Override to reset our saved global current server session.
+ alias_method :teardown_existing, :teardown
+ def teardown
+ teardown_existing
+ PryNav.current_remote_server = nil
+ end
end
end
@@ -92,5 +34,7 @@ def remote_pry(host = 'localhost', port = 9876)
# PryNav::Tracer#run doesn't have a chance to cleanup.
at_exit do
set_trace_func nil
- PryRemote::Server.stop
+ if PryNav.current_remote_server
+ PryNav.current_remote_server.teardown
+ end
end
View
@@ -26,7 +26,9 @@ def run(&block)
start
else
stop if RUBY_VERSION == '1.9.2'
- PryRemote::Server.stop if @pry_start_options[:pry_remote]
+ if @pry_start_options[:pry_remote] && PryNav.current_remote_server
+ PryNav.current_remote_server.teardown
+ end
end
return_value
View
@@ -20,4 +20,5 @@ Gem::Specification.new do |gem|
# Dependencies
gem.required_ruby_version = '>= 1.8.7'
gem.add_runtime_dependency 'pry', '~> 0.9.8.1'
+ gem.add_development_dependency 'pry-remote', '~> 0.1.1'
end

0 comments on commit 4e81c50

Please sign in to comment.