pry-stack_explorer 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -47,6 +47,11 @@ task :example2 do
47
47
  sh "ruby -I#{direc}/lib/ #{direc}/examples/example2.rb "
48
48
  end
49
49
 
50
+ desc "Run example3"
51
+ task :example3 do
52
+ sh "ruby -I#{direc}/lib/ #{direc}/examples/example3.rb "
53
+ end
54
+
50
55
  desc "Show version"
51
56
  task :version do
52
57
  puts "PryStackExplorer version: #{PryStackExplorer::VERSION}"
@@ -0,0 +1,46 @@
1
+ unless Object.const_defined? :PryStackExplorer
2
+ $:.unshift File.expand_path '../../lib', __FILE__
3
+ require 'pry'
4
+ end
5
+
6
+ require 'pry-stack_explorer'
7
+
8
+ def b
9
+ x = 30
10
+ proc {
11
+ c
12
+ }.call
13
+ end
14
+
15
+ def c
16
+ u = 50
17
+ V.new.beta
18
+ end
19
+
20
+ # hello
21
+ class V
22
+ def beta
23
+ gamma
24
+ end
25
+
26
+ def gamma
27
+ zeta
28
+ end
29
+ end
30
+
31
+ def zeta
32
+ vitamin = 100
33
+ binding.pry
34
+ end
35
+ #
36
+
37
+ proc {
38
+ class J
39
+ def alphabet(y)
40
+ x = 20
41
+ b
42
+ end
43
+ end
44
+ }.call
45
+
46
+ J.new.alphabet(122)
@@ -5,7 +5,6 @@ require "pry-stack_explorer/version"
5
5
  require "pry-stack_explorer/commands"
6
6
  require "pry-stack_explorer/frame_manager"
7
7
  require "pry-stack_explorer/when_started_hook"
8
- require "pry"
9
8
  require "binding_of_caller"
10
9
 
11
10
  module PryStackExplorer
@@ -1,5 +1,3 @@
1
- require 'pry'
2
-
3
1
  module PryStackExplorer
4
2
  module FrameHelpers
5
3
  private
@@ -88,6 +86,33 @@ module PryStackExplorer
88
86
 
89
87
  # Regexp.new(args[0])
90
88
  def find_frame_by_regex(regex, up_or_down)
89
+ frame_index = find_frame_by_block(up_or_down) do |b|
90
+ b.eval("__method__").to_s =~ regex
91
+ end
92
+
93
+ if frame_index
94
+ frame_index
95
+ else
96
+ raise Pry::CommandError, "No frame that matches #{regex.source} found!"
97
+ end
98
+ end
99
+
100
+ def find_frame_by_object_regex(class_regex, method_regex, up_or_down)
101
+ frame_index = find_frame_by_block(up_or_down) do |b|
102
+ class_match = b.eval("self.class").to_s =~ class_regex
103
+ meth_match = b.eval("__method__").to_s =~ method_regex
104
+
105
+ class_match && meth_match
106
+ end
107
+
108
+ if frame_index
109
+ frame_index
110
+ else
111
+ raise Pry::CommandError, "No frame that matches #{class_regex.source}" + '#' + "#{method_regex.source} found!"
112
+ end
113
+ end
114
+
115
+ def find_frame_by_block(up_or_down)
91
116
  start_index = frame_manager.binding_index
92
117
 
93
118
  if up_or_down == :down
@@ -97,19 +122,14 @@ module PryStackExplorer
97
122
  end
98
123
 
99
124
  new_frame = enum.find do |b|
100
- b.eval("__method__").to_s =~ regex
125
+ yield(b)
101
126
  end
102
127
 
103
128
  frame_index = frame_manager.bindings.index(new_frame)
104
-
105
- if frame_index
106
- frame_index
107
- else
108
- raise Pry::CommandError, "No frame that matches #{regex.source} found!"
109
- end
110
129
  end
111
130
  end
112
131
 
132
+
113
133
  Commands = Pry::CommandSet.new do
114
134
  create_command "up", "Go up to the caller's context." do
115
135
  include FrameHelpers
@@ -131,6 +151,9 @@ module PryStackExplorer
131
151
  else
132
152
  if inc =~ /\d+/
133
153
  frame_manager.change_frame_to frame_manager.binding_index + inc.to_i
154
+ elsif match = /^([A-Z]+[^#.]*)(#|\.)(.+)$/.match(inc)
155
+ new_frame_index = find_frame_by_object_regex(Regexp.new(match[1]), Regexp.new(match[3]), :up)
156
+ frame_manager.change_frame_to new_frame_index
134
157
  elsif inc =~ /^[^-].*$/
135
158
  new_frame_index = find_frame_by_regex(Regexp.new(inc), :up)
136
159
  frame_manager.change_frame_to new_frame_index
@@ -163,6 +186,9 @@ module PryStackExplorer
163
186
  else
164
187
  frame_manager.change_frame_to frame_manager.binding_index - inc.to_i
165
188
  end
189
+ elsif match = /^([A-Z]+[^#.]*)(#|\.)(.+)$/.match(inc)
190
+ new_frame_index = find_frame_by_object_regex(Regexp.new(match[1]), Regexp.new(match[3]), :down)
191
+ frame_manager.change_frame_to new_frame_index
166
192
  elsif inc =~ /^[^-].*$/
167
193
  new_frame_index = find_frame_by_regex(Regexp.new(inc), :down)
168
194
  frame_manager.change_frame_to new_frame_index
@@ -192,6 +218,9 @@ module PryStackExplorer
192
218
 
193
219
  if args[0] =~ /\d+/
194
220
  frame_manager.change_frame_to args[0].to_i
221
+ elsif match = /^([A-Z]+[^#.]*)(#|\.)(.+)$/.match(args[0])
222
+ new_frame_index = find_frame_by_object_regex(Regexp.new(match[1]), Regexp.new(match[3]), :up)
223
+ frame_manager.change_frame_to new_frame_index
195
224
  elsif args[0] =~ /^[^-].*$/
196
225
  new_frame_index = find_frame_by_regex(Regexp.new(args[0]), :up)
197
226
  frame_manager.change_frame_to new_frame_index
@@ -277,8 +306,8 @@ module PryStackExplorer
277
306
 
278
307
  stagger_output content
279
308
  end
280
-
281
309
  end
310
+
282
311
  end
283
312
  end
284
313
  end
@@ -1,3 +1,3 @@
1
1
  module PryStackExplorer
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pry-stack_explorer"
5
- s.version = "0.4.2"
5
+ s.version = "0.4.3"
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)"]
9
- s.date = "2012-04-18"
9
+ s.date = "2012-07-13"
10
10
  s.description = "Walk the stack in a Pry session"
11
11
  s.email = "jrmair@gmail.com"
12
- s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example.rb", "examples/example2.rb", "lib/pry-stack_explorer.rb", "lib/pry-stack_explorer/commands.rb", "lib/pry-stack_explorer/frame_manager.rb", "lib/pry-stack_explorer/version.rb", "lib/pry-stack_explorer/when_started_hook.rb", "pry-stack_explorer.gemspec", "test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb", "tester.rb"]
12
+ s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example.rb", "examples/example2.rb", "examples/example3.rb", "lib/pry-stack_explorer.rb", "lib/pry-stack_explorer/commands.rb", "lib/pry-stack_explorer/frame_manager.rb", "lib/pry-stack_explorer/version.rb", "lib/pry-stack_explorer/when_started_hook.rb", "pry-stack_explorer.gemspec", "test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb", "tester.rb"]
13
13
  s.homepage = "https://github.com/banister"
14
14
  s.require_paths = ["lib"]
15
- s.rubygems_version = "1.8.16"
15
+ s.rubygems_version = "1.8.24"
16
16
  s.summary = "Walk the stack in a Pry session"
17
17
  s.test_files = ["test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb"]
18
18
 
data/test/helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'ostruct'
3
+ require 'pry'
3
4
 
4
5
  unless Object.const_defined? 'PryStackExplorer'
5
6
  $:.unshift File.expand_path '../../lib', __FILE__
@@ -1,5 +1,39 @@
1
1
  require 'helper'
2
2
 
3
+
4
+ class Top
5
+ attr_accessor :method_list, :middle
6
+ def initialize method_list
7
+ @method_list = method_list
8
+ end
9
+ def bing
10
+ @middle = Middle.new method_list
11
+ @middle.bong
12
+ end
13
+ end
14
+
15
+ class Middle
16
+ attr_accessor :method_list, :bottom
17
+ def initialize method_list
18
+ @method_list = method_list
19
+ end
20
+ def bong
21
+ @bottom = Bottom.new method_list
22
+ @bottom.bang
23
+ end
24
+ end
25
+
26
+ class Bottom
27
+ attr_accessor :method_list
28
+ def initialize method_list
29
+ @method_list = method_list
30
+ end
31
+ def bang
32
+ Pry.start(binding)
33
+ end
34
+ end
35
+
36
+
3
37
  describe PryStackExplorer::Commands do
4
38
 
5
39
  before do
@@ -11,6 +45,9 @@ describe PryStackExplorer::Commands do
11
45
  def @o.bing() bong end
12
46
  def @o.bong() bang end
13
47
  def @o.bang() Pry.start(binding) end
48
+
49
+ method_list = []
50
+ @top = Top.new method_list
14
51
  end
15
52
 
16
53
  after do
@@ -83,6 +120,58 @@ describe PryStackExplorer::Commands do
83
120
  out.string.should =~ /Error: No frame that matches/
84
121
  end
85
122
  end
123
+
124
+
125
+ describe 'by Class#method name regex' do
126
+ it 'should move to the method and class that matches the regex' do
127
+ redirect_pry_io(InputTester.new("@method_list << self.class.to_s + '#' + __method__.to_s",
128
+ 'up Middle#bong',
129
+ "@method_list << self.class.to_s + '#' + __method__.to_s",
130
+ "exit-all"), out=StringIO.new) do
131
+ @top.bing
132
+ end
133
+
134
+ @top.method_list.should == ['Bottom#bang', 'Middle#bong']
135
+ end
136
+
137
+ ### ????? ###
138
+ # it 'should be case sensitive' do
139
+ # end
140
+ ### ????? ###
141
+
142
+ it 'should allow partial class names' do
143
+ redirect_pry_io(InputTester.new("@method_list << self.class.to_s + '#' + __method__.to_s",
144
+ 'up Mid#bong',
145
+ "@method_list << self.class.to_s + '#' + __method__.to_s",
146
+ "exit-all"), out=StringIO.new) do
147
+ @top.bing
148
+ end
149
+
150
+ @top.method_list.should == ['Bottom#bang', 'Middle#bong']
151
+
152
+ end
153
+
154
+ it 'should allow partial method names' do
155
+ redirect_pry_io(InputTester.new("@method_list << self.class.to_s + '#' + __method__.to_s",
156
+ 'up Middle#bo',
157
+ "@method_list << self.class.to_s + '#' + __method__.to_s",
158
+ "exit-all"), out=StringIO.new) do
159
+ @top.bing
160
+ end
161
+
162
+ @top.method_list.should == ['Bottom#bang', 'Middle#bong']
163
+
164
+ end
165
+
166
+ it 'should error if it cant find frame to match regex' do
167
+ redirect_pry_io(InputTester.new('up Conrad#irwin',
168
+ "exit-all"), out=StringIO.new) do
169
+ @top.bing
170
+ end
171
+
172
+ out.string.should =~ /Error: No frame that matches/
173
+ end
174
+ end
86
175
  end
87
176
 
88
177
  describe "down" do
@@ -153,6 +242,34 @@ describe PryStackExplorer::Commands do
153
242
  end
154
243
  end
155
244
 
245
+ describe 'by Class#method name regex' do
246
+ it 'should move to the method and class that matches the regex' do
247
+ redirect_pry_io(InputTester.new('frame Top#bing',
248
+ "@method_list << self.class.to_s + '#' + __method__.to_s",
249
+ 'down Middle#bong',
250
+ "@method_list << self.class.to_s + '#' + __method__.to_s",
251
+ "exit-all"), out=StringIO.new) do
252
+ @top.bing
253
+ end
254
+
255
+ @top.method_list.should == ['Top#bing', 'Middle#bong']
256
+ end
257
+
258
+ ### ????? ###
259
+ # it 'should be case sensitive' do
260
+ # end
261
+ ### ????? ###
262
+
263
+ it 'should error if it cant find frame to match regex' do
264
+ redirect_pry_io(InputTester.new('down Conrad#irwin',
265
+ "exit-all"), out=StringIO.new) do
266
+ @top.bing
267
+ end
268
+
269
+ out.string.should =~ /Error: No frame that matches/
270
+ end
271
+ end
272
+
156
273
  end
157
274
 
158
275
  describe "frame" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-stack_explorer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-18 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: binding_of_caller
16
- requirement: &70234086143460 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.6.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70234086143460
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.6.2
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: pry
27
- requirement: &70234086141020 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.9.9
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70234086141020
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.9
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: bacon
38
- requirement: &70234086155340 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 1.1.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70234086155340
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &70234086154720 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0.9'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70234086154720
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.9'
58
78
  description: Walk the stack in a Pry session
59
79
  email: jrmair@gmail.com
60
80
  executables: []
@@ -72,6 +92,7 @@ files:
72
92
  - Rakefile
73
93
  - examples/example.rb
74
94
  - examples/example2.rb
95
+ - examples/example3.rb
75
96
  - lib/pry-stack_explorer.rb
76
97
  - lib/pry-stack_explorer/commands.rb
77
98
  - lib/pry-stack_explorer/frame_manager.rb
@@ -103,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
124
  version: '0'
104
125
  requirements: []
105
126
  rubyforge_project:
106
- rubygems_version: 1.8.16
127
+ rubygems_version: 1.8.24
107
128
  signing_key:
108
129
  specification_version: 3
109
130
  summary: Walk the stack in a Pry session