Class: PrayRemote::Server
Instance Attribute Summary collapse
-
#client ⇒ PryServer::Client
readonly
Client connecting to the pry-remote server.
-
#host ⇒ String
readonly
Host of the server.
-
#object ⇒ Object
readonly
Object to enter into.
-
#port ⇒ Integer
readonly
Port of the server.
-
#unix ⇒ String
readonly
Unix domain socket path of the server.
-
#uri ⇒ String
readonly
URI for DRab.
Class Method Summary collapse
Instance Method Summary collapse
-
#capture_output ⇒ Object
Captures $stdout and $stderr if so requested by the client.
-
#initialize(object, *args) ⇒ 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.
-
#uncapture_output ⇒ Object
Resets $stdout and $stderr to their previous values.
Constructor Details
#initialize(object, *args) ⇒ Server
Returns a new instance of Server.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/pray-remote/pray-remote.rb', line 260 def initialize(object, *args) = PrayRemote.kwargs(args) @host = [:host] || DefaultHost @port = [:port] || DefaultPort @unix = [:unix] || false @secret = "" if [:secret] != nil @secret = "?secret=" + [:secret] end if @unix == false @uri = "druby://#{@host}:#{@port}#{@secret}" @unix = "" else @uri = "drabunix:#{@unix}" end @object = object @options = @client = PrayRemote::Client.new DRab.start_service @uri, @client end |
Instance Attribute Details
#client ⇒ PryServer::Client (readonly)
Returns Client connecting to the pry-remote server.
372 373 374 |
# File 'lib/pray-remote/pray-remote.rb', line 372 def client @client end |
#host ⇒ String (readonly)
Returns Host of the server.
375 376 377 |
# File 'lib/pray-remote/pray-remote.rb', line 375 def host @host end |
#object ⇒ Object (readonly)
Returns Object to enter into.
369 370 371 |
# File 'lib/pray-remote/pray-remote.rb', line 369 def object @object end |
#port ⇒ Integer (readonly)
Returns Port of the server.
378 379 380 |
# File 'lib/pray-remote/pray-remote.rb', line 378 def port @port end |
#unix ⇒ String (readonly)
Returns Unix domain socket path of the server.
381 382 383 |
# File 'lib/pray-remote/pray-remote.rb', line 381 def unix @unix end |
#uri ⇒ String (readonly)
Returns URI for DRab.
384 385 386 |
# File 'lib/pray-remote/pray-remote.rb', line 384 def uri @uri end |
Class Method Details
.run(object, *args) ⇒ Object
255 256 257 258 |
# File 'lib/pray-remote/pray-remote.rb', line 255 def self.run(object, *args) = PrayRemote.kwargs(args) new(object, ).run end |
Instance Method Details
#capture_output ⇒ Object
Captures $stdout and $stderr if so requested by the client.
342 343 344 345 |
# File 'lib/pray-remote/pray-remote.rb', line 342 def capture_output $stdout = @client.stdout $stderr = @client.stderr end |
#run ⇒ Object
Actually runs pry-remote
354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/pray-remote/pray-remote.rb', line 354 def run STDOUT.puts "[pry-remote] Waiting for client on #{uri}" @client.wait STDOUT.puts "[pry-remote] Client received, starting remote session" setup Pry.start(@object, @options.merge(:input => client.input_proxy, :output => client.output, :hooks => @hooks)) ensure teardown end |
#setup ⇒ Object
Code that has to be called for Pry-remote to work properly
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/pray-remote/pray-remote.rb', line 287 def setup if @client.stdout.nil? @client.stdout = $stdout end if @client.stderr.nil? @client.stderr = $stderr end @hooks = Pry::Hooks.new @hooks.add_hook :before_eval, :pry_remote_capture do capture_output end @hooks.add_hook :after_eval, :pry_remote_uncapture do uncapture_output end @hooks.add_hook :before_session, :pry_instance_get do |output, bind, mypry| #puts mypry.class #puts mypry.methods @client.mypry = mypry 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 = PrayRemote::System, Pry.config.system Pry.config.editor, @old_editor = nil, Pry.config.editor #binding.pry # for testing attacks on clients end |
#teardown ⇒ Object
Code that has to be called after setup to return to the initial state
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/pray-remote/pray-remote.rb', line 323 def teardown # Reset config Pry.config.editor = @old_editor Pry.config.pager = @old_pager Pry.config.system = @old_system STDOUT.puts "[pry-remote] Remote session terminated" begin @client.kill rescue DRab::DRabConnError STDOUT.puts "[pry-remote] Continuing to stop service" ensure STDOUT.puts "[pry-remote] Ensure stop service" DRab.stop_service end end |
#uncapture_output ⇒ Object
Resets $stdout and $stderr to their previous values.
348 349 350 351 |
# File 'lib/pray-remote/pray-remote.rb', line 348 def uncapture_output $stdout = STDOUT $stderr = STDOUT end |