pry-stack_explorer 0.3.7 → 0.3.8
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.
- data/lib/pry-stack_explorer/commands.rb +18 -6
- data/lib/pry-stack_explorer/version.rb +1 -1
- data/pry-stack_explorer.gemspec +1 -1
- data/test/test_commands.rb +23 -0
- metadata +1 -1
@@ -218,12 +218,13 @@ module PryStackExplorer
|
|
218
218
|
|
219
219
|
banner <<-BANNER
|
220
220
|
Usage: frame [OPTIONS]
|
221
|
-
Switch to a particular frame. Accepts numeric parameter for the target frame to switch to (use with show-stack).
|
222
|
-
When given no parameter show information about the current frame.
|
221
|
+
Switch to a particular frame. Accepts numeric parameter (or regex for method name) for the target frame to switch to (use with show-stack).
|
222
|
+
Negative frame numbers allowed. When given no parameter show information about the current frame.
|
223
223
|
|
224
|
-
e.g: frame 4
|
225
|
-
e.g: frame
|
226
|
-
e.g: frame
|
224
|
+
e.g: frame 4 #=> jump to the 4th frame
|
225
|
+
e.g: frame meth #=> jump to nearest parent stack frame whose method matches /meth/ regex, i.e `my_method`
|
226
|
+
e.g: frame -2 #=> jump to the second-to-last frame
|
227
|
+
e.g: frame #=> show information info about current frame
|
227
228
|
BANNER
|
228
229
|
|
229
230
|
def process
|
@@ -231,8 +232,19 @@ module PryStackExplorer
|
|
231
232
|
raise Pry::CommandError, "nowhere to go!"
|
232
233
|
else
|
233
234
|
|
234
|
-
if args[0]
|
235
|
+
if args[0] =~ /\d+/
|
235
236
|
frame_manager.change_frame_to args[0].to_i
|
237
|
+
elsif args[0] =~ /^[^-].*$/
|
238
|
+
new_frame_index = frame_manager.each_with_index.find_index do |b, i|
|
239
|
+
b.eval("__method__").to_s =~ Regexp.new(args[0]) && i > frame_manager.binding_index
|
240
|
+
end
|
241
|
+
|
242
|
+
if new_frame_index
|
243
|
+
frame_manager.change_frame_to new_frame_index
|
244
|
+
else
|
245
|
+
raise Pry::CommandError, "No parent frame that matches #{args[0]} found!"
|
246
|
+
end
|
247
|
+
|
236
248
|
else
|
237
249
|
output.puts "##{frame_manager.binding_index} #{frame_info(target, true)}"
|
238
250
|
end
|
data/pry-stack_explorer.gemspec
CHANGED
data/test/test_commands.rb
CHANGED
@@ -78,6 +78,29 @@ describe PryStackExplorer::Commands do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
describe "frame" do
|
81
|
+
describe "by method name regex" do
|
82
|
+
it 'should jump to correct stack frame when given method name' do
|
83
|
+
redirect_pry_io(InputTester.new("frame bi",
|
84
|
+
"@first_method = __method__",
|
85
|
+
"exit-all"), out=StringIO.new) do
|
86
|
+
@o.bing
|
87
|
+
end
|
88
|
+
|
89
|
+
@o.first_method.should == :bing
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should NOT jump to frames lower down stack when given method name' do
|
93
|
+
redirect_pry_io(InputTester.new("frame -1",
|
94
|
+
"frame bang",
|
95
|
+
"exit-all"), out=StringIO.new) do
|
96
|
+
@o.bing
|
97
|
+
end
|
98
|
+
|
99
|
+
out.string.should =~ /Error: No parent frame that matches/
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
81
104
|
it 'should move to the given frame in the call stack' do
|
82
105
|
redirect_pry_io(InputTester.new("frame 2",
|
83
106
|
"@first_method = __method__",
|