pry-remote 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +58 -0
- data/bin/pry-remote +4 -0
- data/lib/pry-remote.rb +109 -0
- metadata +77 -0
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# What is it?
|
2
|
+
|
3
|
+
A way to start Pry remotely and to connect to it using DRb. This allows to
|
4
|
+
access the state of the running program from anywhere.
|
5
|
+
|
6
|
+
# Installation
|
7
|
+
|
8
|
+
gem install pry-remote
|
9
|
+
|
10
|
+
# Usage
|
11
|
+
|
12
|
+
Here's a program starting pry-remote:
|
13
|
+
|
14
|
+
require 'pry-remote'
|
15
|
+
|
16
|
+
class Foo
|
17
|
+
def initialize(x, y)
|
18
|
+
binding.remote_pry
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Foo.new 10, 20
|
23
|
+
|
24
|
+
Running it will prompt you with a message telling you Pry is waiting for a
|
25
|
+
program to connect itself to it:
|
26
|
+
|
27
|
+
[pry-remote] Waiting for client on drb://localhost:9876
|
28
|
+
|
29
|
+
You can then connect yourself using ``pry-remote``:
|
30
|
+
|
31
|
+
$ pry-remote
|
32
|
+
From: example.rb @ line 7 in Foo#initialize:
|
33
|
+
2:
|
34
|
+
3: require 'pry-remote'
|
35
|
+
4:
|
36
|
+
5: class Foo
|
37
|
+
6: def initialize(x, y)
|
38
|
+
=> 7: binding.remote_pry
|
39
|
+
8: end
|
40
|
+
9: end
|
41
|
+
10:
|
42
|
+
11: Foo.new 10, 20
|
43
|
+
pry(#<Foo:0x00000000d9b5e8>):1> self
|
44
|
+
=> #<Foo:0x1efb3b0>
|
45
|
+
pry(#<Foo:0x00000001efb3b0>):2> ls -l
|
46
|
+
Local variables: [
|
47
|
+
[0] :_,
|
48
|
+
[1] :_dir_,
|
49
|
+
[2] :_file_,
|
50
|
+
[3] :_ex_,
|
51
|
+
[4] :_pry_,
|
52
|
+
[5] :_out_,
|
53
|
+
[6] :_in_,
|
54
|
+
[7] :x,
|
55
|
+
[8] :y
|
56
|
+
]
|
57
|
+
pry(#<Foo:0x00000001efb3b0>):3> ^D
|
58
|
+
|
data/bin/pry-remote
ADDED
data/lib/pry-remote.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'slop'
|
3
|
+
require 'drb'
|
4
|
+
require 'readline'
|
5
|
+
|
6
|
+
module PryRemote
|
7
|
+
# A class to represent an input object created from DRb. This is used because
|
8
|
+
# Pry checks for arity to know if a prompt should be passed to the object.
|
9
|
+
#
|
10
|
+
# @attr [#readline] input Object to proxy
|
11
|
+
InputProxy = Struct.new :input do
|
12
|
+
# Reads a line from the input
|
13
|
+
def readline(prompt)
|
14
|
+
input.readline(prompt)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# A client is used to retrieve information from the client program.
|
19
|
+
Client = Struct.new :input, :output, :thread do
|
20
|
+
# Waits until both an input and output are set
|
21
|
+
def wait
|
22
|
+
sleep 0.01 until input and output and thread
|
23
|
+
end
|
24
|
+
|
25
|
+
# Tells the client the session is terminated
|
26
|
+
def kill
|
27
|
+
thread.run
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [InputProxy] Proxy for the input
|
31
|
+
def input_proxy
|
32
|
+
InputProxy.new input
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Parses arguments and allows to start the client.
|
37
|
+
class CLI
|
38
|
+
def initialize(args = ARGV)
|
39
|
+
params = Slop.parse args, :help => true do
|
40
|
+
banner "#$PROGRAM_NAME [-h HOST] [-p PORT]"
|
41
|
+
|
42
|
+
on :h, :host, "Host of the server (localhost)", true,
|
43
|
+
:default => "localhost"
|
44
|
+
on :p, :port, "Port of the server (9876)", true, :as => Integer,
|
45
|
+
:default => 9876
|
46
|
+
end
|
47
|
+
|
48
|
+
@host = params[:host]
|
49
|
+
@port = params[:port]
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [String] Host of the server
|
53
|
+
attr_reader :host
|
54
|
+
|
55
|
+
# @return [Integer] Port of the server
|
56
|
+
attr_reader :port
|
57
|
+
|
58
|
+
# @return [String] URI for DRb
|
59
|
+
def uri
|
60
|
+
"druby://#{host}:#{port}"
|
61
|
+
end
|
62
|
+
|
63
|
+
# Connects to the server
|
64
|
+
def run
|
65
|
+
DRb.start_service
|
66
|
+
client = DRbObject.new(nil, uri)
|
67
|
+
|
68
|
+
# Passing Readline to DRb won't actually make it use our readline
|
69
|
+
# object. Instead, it will use the server-side readilne. Therefore, we
|
70
|
+
# create a simple proxy here.
|
71
|
+
|
72
|
+
input = Object.new
|
73
|
+
def input.readline(prompt)
|
74
|
+
Readline.readline(prompt, true)
|
75
|
+
end
|
76
|
+
|
77
|
+
client.input = input
|
78
|
+
client.output = $stdout
|
79
|
+
client.thread = Thread.current
|
80
|
+
|
81
|
+
sleep
|
82
|
+
DRb.stop_service
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Object
|
88
|
+
# Starts a remote Pry session
|
89
|
+
#
|
90
|
+
# @param [String] host Host of the server
|
91
|
+
# @param [Integer] port Port of the server
|
92
|
+
def remote_pry(host = "localhost", port = 9876)
|
93
|
+
uri = "druby://#{host}:#{port}"
|
94
|
+
|
95
|
+
client = PryRemote::Client.new
|
96
|
+
DRb.start_service uri, client
|
97
|
+
|
98
|
+
puts "[pry-remote] Waiting for client on #{uri}"
|
99
|
+
client.wait
|
100
|
+
|
101
|
+
puts "[pry-remote] Client received, starting remote sesion"
|
102
|
+
Pry.start(self, :input => client.input_proxy, :output => client.output)
|
103
|
+
|
104
|
+
puts "[pry-remote] Remote sesion terminated"
|
105
|
+
client.kill
|
106
|
+
|
107
|
+
DRb.stop_service
|
108
|
+
end
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry-remote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mon ouie
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-11 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: slop
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.1"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: pry
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0.9"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
description: Connect to Pry remotely using DRb
|
38
|
+
email: mon.ouie@gmail.com
|
39
|
+
executables:
|
40
|
+
- pry-remote
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- lib/pry-remote.rb
|
47
|
+
- README.md
|
48
|
+
- bin/pry-remote
|
49
|
+
homepage: http://github.com/Mon-Ouie/pry-remote
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.6
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Connect to Pry remotely
|
76
|
+
test_files: []
|
77
|
+
|