Class: PryRemote::Server
Instance Attribute Summary collapse
-
#client ⇒ PryServer::Client
readonly
Client connecting to the pry-remote server.
-
#object ⇒ Object
readonly
Object to enter into.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, host = DefaultHost, port = DefaultPort) ⇒ Server
constructor
A new instance of Server.
-
#run ⇒ Object
Actually runs pry-remote.
-
#setup ⇒ Object
Code that has to be called for Pry-remote to work properly.
-
#teardown ⇒ Object
Code that has to be called after setup to return to the initial state.
Constructor Details
#initialize(object, host = DefaultHost, port = DefaultPort) ⇒ Server
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pry-remote.rb', line 135 def initialize(object, host = DefaultHost, port = DefaultPort) @uri = "druby://#{host}:#{port}" @object = object @client = PryRemote::Client.new DRb.start_service @uri, @client puts "[pry-remote] Waiting for client on #@uri" @client.wait puts "[pry-remote] Client received, starting remote session" end |
Instance Attribute Details
#client ⇒ PryServer::Client (readonly)
208 209 210 |
# File 'lib/pry-remote.rb', line 208 def client @client end |
#object ⇒ Object (readonly)
205 206 207 |
# File 'lib/pry-remote.rb', line 205 def object @object end |
Class Method Details
.run(object, host = DefaultHost, port = DefaultPort) ⇒ Object
131 132 133 |
# File 'lib/pry-remote.rb', line 131 def self.run(object, host = DefaultHost, port = DefaultPort) new(object, host, port).run end |
Instance Method Details
#run ⇒ Object
Actually runs pry-remote
197 198 199 200 201 202 |
# File 'lib/pry-remote.rb', line 197 def run setup Pry.start(@object, :input => client.input_proxy, :output => client.output) ensure teardown end |
#setup ⇒ Object
Code that has to be called for Pry-remote to work properly
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/pry-remote.rb', line 149 def setup # 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 end |
#teardown ⇒ Object
Code that has to be called after setup to return to the initial state
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/pry-remote.rb', line 173 def teardown # Reset output streams $stdout = @old_stdout $stderr = @old_stderr # Reset config Pry.config.pager = @old_pager # Reset sysem Pry.config.system = @old_system puts "[pry-remote] Remote session terminated" begin @client.kill rescue DRb::DRbConnError puts "[pry-remote] Continuing to stop service" ensure puts "[pry-remote] Ensure stop service" DRb.stop_service end end |