pry-shell 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 339b96b3477c3abfe68e09e2112a2c4d59a533466d2d800174fe1d255530e84f
4
- data.tar.gz: 47cede13047e2c16cc427f75fe9333600620a6a7703f259fb8e0c378a77b183e
3
+ metadata.gz: 68f90c4cdfe746f83fe8d18649b1141a901b5ba38d1a200b74556c066dd6fa6f
4
+ data.tar.gz: a1849f725f15e7f639968d7145c5a48efb72b351118e745b3e804c0b0d37062d
5
5
  SHA512:
6
- metadata.gz: e9e426725066c6653d8a5c14e5ff2df0ecfb56fcfa0368e96ea6ca7b1fccab3ba42be1b07cb67b4e705f26275e59af59c74a52e0fbf74b2bde6aec895fe4cec8
7
- data.tar.gz: 46ec623b15d359d3d108c94697a088cb094bf27ae9885be6177f390baad36f5cd09c9be87561002e78ce43f05563c5aeee210bec24fa03cc044628682677f675
6
+ metadata.gz: 9e7468ba04ac804e48428f95cf9ac1ffc6301dfef9c28d1b76d83d1e9816b2159f39a512c18a139f1aba8b79ae48929cb7b14d4daf65143e5a87f645e80b1889
7
+ data.tar.gz: 2f96b7544443dc1f2699d6e6da2e8165243e3d5617bbcc27493fe3d5da9d65c9d86a840f000c3aa2ef277e904aab6b0eba595e11a34f7b5396ad8e712640ccd2
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /log/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in pry-shell.gemspec
6
6
  gemspec
7
7
 
8
+ gem "pry-byebug"
8
9
  gem "rake", "~> 13.0"
9
10
  gem "rspec", "~> 3.0"
10
11
  gem "rubocop", "~> 1.7"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-shell (0.3.0)
4
+ pry-shell (0.4.0)
5
5
  pry (~> 0.13.0)
6
6
  tty-markdown
7
7
  tty-prompt
@@ -10,6 +10,7 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
+ byebug (11.1.3)
13
14
  coderay (1.1.3)
14
15
  diff-lcs (1.4.4)
15
16
  kramdown (2.3.1)
@@ -23,6 +24,9 @@ GEM
23
24
  pry (0.13.1)
24
25
  coderay (~> 1.1)
25
26
  method_source (~> 1.0)
27
+ pry-byebug (3.9.0)
28
+ byebug (~> 11.0)
29
+ pry (~> 0.13.0)
26
30
  rainbow (3.0.0)
27
31
  rake (13.0.3)
28
32
  regexp_parser (2.1.1)
@@ -83,6 +87,7 @@ PLATFORMS
83
87
  x86_64-darwin-19
84
88
 
85
89
  DEPENDENCIES
90
+ pry-byebug
86
91
  pry-shell!
87
92
  rake (~> 13.0)
88
93
  rspec (~> 3.0)
data/bin/console CHANGED
@@ -11,6 +11,20 @@ require "pry/shell"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- a = 1
14
+ def foo1
15
+ binding.pry_shell(with_byebug: true)
15
16
 
16
- binding.pry_shell
17
+ foo2
18
+ end
19
+
20
+ def foo2
21
+ foo3
22
+ end
23
+
24
+ def foo3
25
+ 5
26
+ end
27
+
28
+ a = 5 + foo1
29
+
30
+ puts a
data/lib/pry/shell.rb CHANGED
@@ -31,6 +31,8 @@ class Pry
31
31
  def run
32
32
  run_server
33
33
  draw_ui
34
+ rescue TTY::Reader::InputInterrupt, Interrupt
35
+ exit
34
36
  end
35
37
 
36
38
  def active_shell_options(thread: Thread.current)
@@ -41,6 +43,14 @@ class Pry
41
43
  Thread.current[:active_shell_options] = value
42
44
  end
43
45
 
46
+ def clear_shell_options!
47
+ self.active_shell_options = nil
48
+ end
49
+
50
+ def remove_active_connection!
51
+ active_shell_options&.fetch(:remove_connection)&.call
52
+ end
53
+
44
54
  def configuration
45
55
  @configuration ||= Configuration.new
46
56
  end
@@ -7,7 +7,7 @@ require "fileutils"
7
7
  class Pry
8
8
  class Shell
9
9
  class Logger
10
- LOG_FOLDER = "tmp"
10
+ LOG_FOLDER = "log"
11
11
 
12
12
  class << self
13
13
  extend Forwardable
@@ -4,8 +4,8 @@ class Pry
4
4
  class Shell
5
5
  module Patches
6
6
  module Object
7
- def pry_shell(host: DEFAULT_HOST, port: DEFAULT_PORT)
8
- Session.run(self, host: host, port: port)
7
+ def pry_shell(host: DEFAULT_HOST, port: DEFAULT_PORT, with_byebug: false)
8
+ Session.run(self, host: host, port: port, with_byebug: with_byebug)
9
9
  end
10
10
  end
11
11
  end
@@ -1,22 +1,73 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Pry
4
- class Shell
5
- module Patches
6
- module PryByebug
7
- def start_with_pry_byebug(target = nil, options = {})
8
- return start_without_pry_byebug(target, options) if Shell.active_shell_options
9
-
10
- super
3
+ begin
4
+ require "pry-byebug"
5
+ require "pry-byebug/pry_ext"
6
+
7
+ module Byebug
8
+ class PryShellProcessor < PryProcessor
9
+ class << self
10
+ def start
11
+ Byebug.start
12
+ Setting[:autolist] = false
13
+ Context.processor = self
14
+ Byebug.current_context.step_out(7, true)
15
+ at_exit { teardown! }
16
+ end
17
+
18
+ private
19
+
20
+ def teardown!
21
+ Pry::Shell.remove_active_connection!
22
+ Pry::Shell.clear_shell_options!
11
23
  end
12
24
  end
25
+
26
+ def resume_pry
27
+ run do
28
+ pry_started? ? start_new_pry_repl : start_new_pry_session
29
+ end
30
+ rescue DRb::DRbConnError
31
+ puts "DRb connection failed!"
32
+ end
33
+
34
+ private
35
+
36
+ def pry_started?
37
+ defined?(@pry) && @pry
38
+ end
39
+
40
+ def start_new_pry_session
41
+ @pry = Pry.start_without_pry_byebug(frame._binding, Pry::Shell.active_shell_options)
42
+ end
43
+
44
+ def start_new_pry_repl
45
+ Pry::Shell::Repl.new(@pry, target: frame._binding).start
46
+ end
13
47
  end
14
48
  end
15
- end
16
49
 
17
- begin
18
- require "pry-byebug"
19
- require "pry-byebug/pry_ext"
50
+ class Pry
51
+ class Shell
52
+ module Patches
53
+ module PryByebug
54
+ def start_with_pry_byebug(target = nil, options = {})
55
+ return start_with_pry_shell(target) if Shell.active_shell_options
56
+
57
+ super
58
+ end
59
+
60
+ def start_with_pry_shell(target)
61
+ if Shell.active_shell_options[:with_byebug]
62
+ ::Byebug::PryShellProcessor.start
63
+ else
64
+ start_without_pry_byebug(target, Shell.active_shell_options)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
20
71
 
21
72
  Pry.singleton_class.prepend(Pry::Shell::Patches::PryByebug)
22
73
  Pry.singleton_class.alias_method(:start, :start_with_pry_byebug)
@@ -13,15 +13,16 @@ class Pry
13
13
  class Shell
14
14
  class Session
15
15
  class << self
16
- def run(object, host:, port:)
17
- new(object, host, port).run
16
+ def run(object, host:, port:, with_byebug:)
17
+ new(object, host, port, with_byebug).run
18
18
  end
19
19
  end
20
20
 
21
- def initialize(object, host, port)
21
+ def initialize(object, host, port, with_byebug)
22
22
  @object = object
23
23
  @host = host
24
24
  @port = port
25
+ @with_byebug = with_byebug
25
26
  end
26
27
 
27
28
  def run
@@ -31,15 +32,22 @@ class Pry
31
32
  rescue DRb::DRbConnError
32
33
  puts "DRb connection failed!"
33
34
  ensure
34
- Shell.active_shell_options = nil
35
+ # Since we run `Byebug.current_context.step_out` this ensure
36
+ # block already runs and clears the options which are necessary
37
+ # to setup the Byebug.
38
+ # We are clearing this options in `PryShellProcessor` to ensure
39
+ # they do not leak.
40
+ Shell.clear_shell_options! unless with_byebug
35
41
  end
36
42
 
37
43
  private
38
44
 
39
- attr_reader :object, :host, :port
45
+ attr_reader :object, :host, :port, :with_byebug
40
46
 
41
47
  def pry_options
42
48
  {
49
+ remove_connection: -> { registry.remove(client) },
50
+ with_byebug: with_byebug,
43
51
  driver: Pry::Shell::Repl,
44
52
  pager: false,
45
53
  input: client.input,
@@ -9,7 +9,7 @@ class Pry
9
9
  pry-shell version "#{VERSION}"
10
10
 
11
11
  Pry-shell provides you a standalone shell for accessing multiple `pry` sessions running on different processes.
12
- You can switch between sessions by using the "\\h" command.
12
+ You can switch between sessions by going back to the menu using the "\\m" command.
13
13
 
14
14
  Written by Mehmet Emin INAC.
15
15
  MARKDOWN
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Pry
4
4
  class Shell
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Emin INAC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-15 00:00:00.000000000 Z
11
+ date: 2021-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry