Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Commit 903ce52

Browse files
committed
Create a new command registry for jard
Pry::Commands aka Pry.config.commands is the registry that Pry uses to store declared commands. Jard implements a lot of custom commands. If it uses Pry::Commands, any binding.pry triggered later includes Jard's specific commands. That leads to a forever error loop.
1 parent 071efa0 commit 903ce52

20 files changed

+220
-40
lines changed

lib/ruby_jard.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
require 'ruby_jard/keys'
1414
require 'ruby_jard/key_binding'
1515
require 'ruby_jard/key_bindings'
16+
require 'ruby_jard/repl_processor'
1617
require 'ruby_jard/repl_manager'
1718
require 'ruby_jard/screen_manager'
1819
require 'ruby_jard/reflection'

lib/ruby_jard/commands/continue_command.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def process
1616
end
1717
end
1818

19-
Pry::Commands.add_command(RubyJard::Commands::ContinueCommand)
20-
Pry::Commands.alias_command 'c', 'continue'
19+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::ContinueCommand)
20+
RubyJard::PryProxy::Commands.alias_command 'c', 'continue'

lib/ruby_jard/commands/down_command.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def process
1919
end
2020
end
2121

22-
Pry::Commands.add_command(RubyJard::Commands::DownCommand)
22+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::DownCommand)

lib/ruby_jard/commands/exit_command.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ def process
1616
end
1717
end
1818

19-
Pry::Commands.add_command(RubyJard::Commands::ExitCommand)
19+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::ExitCommand)

lib/ruby_jard/commands/frame_command.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ def process
2626
end
2727
end
2828

29-
Pry::Commands.add_command(RubyJard::Commands::FrameCommand)
29+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::FrameCommand)

lib/ruby_jard/commands/help_command.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ def help_text_with_sub_commands(commands)
9393
end
9494
end
9595

96-
Pry::Commands.add_command(RubyJard::Commands::HelpCommand)
96+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::HelpCommand)

lib/ruby_jard/commands/jard_command.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ def process
4949
end
5050
end
5151

52-
Pry::Commands.add_command(RubyJard::Commands::JardCommand)
52+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::JardCommand)

lib/ruby_jard/commands/list_command.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def process
1616
end
1717
end
1818

19-
Pry::Commands.add_command(RubyJard::Commands::ListCommand)
20-
Pry::Commands.alias_command 'l', 'list'
21-
Pry::Commands.alias_command 'whereami', 'list'
19+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::ListCommand)
20+
RubyJard::PryProxy::Commands.alias_command 'l', 'list'
21+
RubyJard::PryProxy::Commands.alias_command 'whereami', 'list'

lib/ruby_jard/commands/next_command.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ def process
2020
end
2121
end
2222

23-
Pry::Commands.add_command(RubyJard::Commands::NextCommand)
24-
Pry::Commands.alias_command 'n', 'next'
23+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::NextCommand)
24+
RubyJard::PryProxy::Commands.alias_command 'n', 'next'

lib/ruby_jard/commands/skip_command.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ def process
2727
end
2828
end
2929

30-
Pry::Commands.add_command(RubyJard::Commands::SkipCommand)
30+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::SkipCommand)

lib/ruby_jard/commands/step_command.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ def process
2020
end
2121
end
2222

23-
Pry::Commands.add_command(RubyJard::Commands::StepCommand)
24-
Pry::Commands.alias_command 's', 'step'
23+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::StepCommand)
24+
RubyJard::PryProxy::Commands.alias_command 's', 'step'

lib/ruby_jard/commands/step_out_command.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ def process
2020
end
2121
end
2222

23-
Pry::Commands.add_command(RubyJard::Commands::StepOutCommand)
24-
Pry::Commands.alias_command 'so', 'step-out'
23+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::StepOutCommand)
24+
RubyJard::PryProxy::Commands.alias_command 'so', 'step-out'

lib/ruby_jard/commands/up_command.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def process
2020
end
2121
end
2222

23-
Pry::Commands.add_command(RubyJard::Commands::UpCommand)
23+
RubyJard::PryProxy::Commands.add_command(RubyJard::Commands::UpCommand)

lib/ruby_jard/pry_proxy.rb

+20-2
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ def pry_jard_prompt
9898
end
9999

100100
def pry_command_set
101-
# TODO: Create a dedicated registry to store Jard commands, and merge with Pry default commands
102-
# This approach allows Jard and Binding.pry co-exist even after Jard already started
103101
set = Pry::CommandSet.new
104102
set.import_from(
105103
Pry::Commands,
106104
*(Pry::Commands.list_commands - PRY_EXCLUDED_COMMANDS)
107105
)
106+
set.import_from(
107+
PryProxy::Commands,
108+
*PryProxy::Commands.list_commands
109+
)
108110
set
109111
end
110112

@@ -127,3 +129,19 @@ def pry_hooks
127129
end
128130

129131
RubyJard::PryProxy.init
132+
133+
require 'ruby_jard/commands/base_command'
134+
require 'ruby_jard/commands/validation_helpers'
135+
require 'ruby_jard/commands/color_helpers'
136+
require 'ruby_jard/commands/continue_command'
137+
require 'ruby_jard/commands/exit_command'
138+
require 'ruby_jard/commands/up_command'
139+
require 'ruby_jard/commands/down_command'
140+
require 'ruby_jard/commands/next_command'
141+
require 'ruby_jard/commands/step_command'
142+
require 'ruby_jard/commands/step_out_command'
143+
require 'ruby_jard/commands/frame_command'
144+
require 'ruby_jard/commands/list_command'
145+
require 'ruby_jard/commands/skip_command'
146+
require 'ruby_jard/commands/jard_command'
147+
require 'ruby_jard/commands/help_command'

lib/ruby_jard/repl_processor.rb

-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'ruby_jard/commands/base_command'
4-
require 'ruby_jard/commands/validation_helpers'
5-
require 'ruby_jard/commands/color_helpers'
6-
require 'ruby_jard/commands/continue_command'
7-
require 'ruby_jard/commands/exit_command'
8-
require 'ruby_jard/commands/up_command'
9-
require 'ruby_jard/commands/down_command'
10-
require 'ruby_jard/commands/next_command'
11-
require 'ruby_jard/commands/step_command'
12-
require 'ruby_jard/commands/step_out_command'
13-
require 'ruby_jard/commands/frame_command'
14-
require 'ruby_jard/commands/list_command'
15-
require 'ruby_jard/commands/skip_command'
16-
require 'ruby_jard/commands/jard_command'
17-
require 'ruby_jard/commands/help_command'
18-
193
module RubyJard
204
##
215
# Byebug allows customizing processor with a series of hooks (https://github.com/deivid-rodriguez/byebug/blob/e1fb8209d56922f7bafd128af84e61568b6cd6a7/lib/byebug/processors/command_processor.rb)

lib/ruby_jard/session.rb

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def start
5757
Byebug::Setting[:autoirb] = false
5858
Byebug::Setting[:autopry] = false
5959

60-
require 'ruby_jard/repl_processor'
6160
Byebug::Context.processor = RubyJard::ReplProcessor
6261
# Exclude all files in Ruby Jard source code from the stacktrace.
6362
Byebug::Context.ignored_files = Byebug::Context.all_files + RubyJard.all_files
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require 'ruby_jard'
4+
5+
class SubCalculator
6+
def calculate(d)
7+
d1 = d * 2
8+
jard
9+
d2 = d * 2
10+
d1 + d2
11+
end
12+
end
13+
14+
class Calculator
15+
def calculate(a, b, c)
16+
jard
17+
d = a + b
18+
binding.pry
19+
e = SubCalculator.new.calculate(d)
20+
binding.pry
21+
e + c
22+
end
23+
end
24+
25+
Calculator.new.calculate(1, 2, 3)

spec/integration/compatibilities/compatibilities_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,28 @@
5656
test.stop
5757
end
5858
end
59+
60+
context 'when attach into program with mixed binding.pry and jard command' do
61+
it 'binding.pry command still works along with Jard' do
62+
test = JardIntegrationTest.new(
63+
self, work_dir,
64+
'compatibility_binding_pry_mixed.expected',
65+
"bundle exec ruby #{RSPEC_ROOT}/examples/binding_pry_mixed_example.rb",
66+
width: 130, height: 30
67+
)
68+
test.start
69+
test.assert_screen
70+
71+
test.send_keys('continue', :Enter)
72+
test.assert_screen
73+
74+
test.send_keys('exit', :Enter)
75+
test.assert_screen
76+
77+
test.send_keys('continue', :Enter)
78+
test.assert_screen
79+
ensure
80+
test.stop
81+
end
82+
end
5983
end

0 commit comments

Comments
 (0)