pry-stack_explorer 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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). Negative frame numbers allowed.
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 #=> jump to the 4th frame
225
- e.g: frame -2 #=> jump to the second-to-last frame
226
- e.g: frame #=> show information info about current 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
@@ -1,3 +1,3 @@
1
1
  module PryStackExplorer
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pry-stack_explorer"
5
- s.version = "0.3.7"
5
+ s.version = "0.3.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Mair (banisterfiend)"]
@@ -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__",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pry-stack_explorer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.7
5
+ version: 0.3.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Mair (banisterfiend)