pry-stack_explorer 0.2.9pre1 → 0.2.9pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pry-stack_explorer.rb +16 -6
- data/lib/pry-stack_explorer/commands.rb +1 -1
- data/lib/pry-stack_explorer/frame_manager.rb +5 -0
- data/lib/pry-stack_explorer/version.rb +1 -1
- data/pry-stack_explorer.gemspec +12 -12
- data/test/test_commands.rb +1 -1
- data/test/test_stack_explorer.rb +58 -3
- metadata +44 -51
data/lib/pry-stack_explorer.rb
CHANGED
@@ -9,6 +9,12 @@ require "binding_of_caller"
|
|
9
9
|
|
10
10
|
module PryStackExplorer
|
11
11
|
|
12
|
+
# @return [Hash] The hash storing all frames for all Pry instances for
|
13
|
+
# the current thread
|
14
|
+
def self.frame_hash
|
15
|
+
Thread.current[:__pry_frame_managers__]
|
16
|
+
end
|
17
|
+
|
12
18
|
def self.init_frame_hash
|
13
19
|
Thread.current[:__pry_frame_managers__] ||= Hash.new { |h, k| h[k] = [] }
|
14
20
|
end
|
@@ -19,7 +25,7 @@ module PryStackExplorer
|
|
19
25
|
# @param [Pry] _pry_ The Pry instance associated with the frame manager
|
20
26
|
def self.create_and_push_frame_manager(bindings, _pry_)
|
21
27
|
init_frame_hash
|
22
|
-
|
28
|
+
frame_hash[_pry_].push FrameManager.new(bindings, _pry_)
|
23
29
|
end
|
24
30
|
|
25
31
|
# Return the complete frame manager stack for the Pry instance
|
@@ -28,21 +34,25 @@ module PryStackExplorer
|
|
28
34
|
# @return [Array] The stack of Pry::FrameManager objections
|
29
35
|
def self.frame_managers(_pry_)
|
30
36
|
init_frame_hash
|
31
|
-
|
37
|
+
frame_hash[_pry_]
|
32
38
|
end
|
33
39
|
|
34
40
|
# Delete the currently active frame manager
|
35
41
|
# @param [Pry] _pry_ The Pry instance associated with the frame managers
|
36
42
|
def self.pop_frame_manager(_pry_)
|
37
43
|
init_frame_hash
|
38
|
-
|
44
|
+
popped = frame_managers(_pry_).pop
|
45
|
+
frame_hash.delete(_pry_) if frame_managers(_pry_).empty?
|
46
|
+
_pry_.backtrace = popped.prior_backtrace
|
47
|
+
popped
|
39
48
|
end
|
40
49
|
|
41
50
|
# Clear the stack of frame managers for the Pry instance
|
42
51
|
# @param [Pry] _pry_ The Pry instance associated with the frame managers
|
43
52
|
def self.clear_frame_managers(_pry_)
|
44
53
|
init_frame_hash
|
45
|
-
|
54
|
+
pop_frame_manager(_pry_) until frame_managers(_pry_).empty?
|
55
|
+
frame_hash.delete(_pry_) # this line should be unnecessary!
|
46
56
|
end
|
47
57
|
|
48
58
|
class << self; alias_method :delete_frame_managers, :clear_frame_managers; end
|
@@ -50,7 +60,7 @@ module PryStackExplorer
|
|
50
60
|
# @return [PryStackExplorer::FrameManager] The currently active frame manager
|
51
61
|
def self.frame_manager(_pry_)
|
52
62
|
init_frame_hash
|
53
|
-
|
63
|
+
frame_hash[_pry_].last
|
54
64
|
end
|
55
65
|
|
56
66
|
# Simple test to check whether two `Binding` objects are equal.
|
@@ -104,7 +114,7 @@ Pry.config.hooks.add_hook(:when_started, :save_caller_bindings) do |binding_stac
|
|
104
114
|
end
|
105
115
|
|
106
116
|
# Import the StackExplorer commands
|
107
|
-
Pry.config.commands.import PryStackExplorer::
|
117
|
+
Pry.config.commands.import PryStackExplorer::Commands
|
108
118
|
|
109
119
|
# monkey-patch the whereami command to show some frame information,
|
110
120
|
# useful for navigating stack.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'pry'
|
2
2
|
|
3
3
|
module PryStackExplorer
|
4
|
-
|
4
|
+
Commands = Pry::CommandSet.new do
|
5
5
|
command "up", "Go up to the caller's context. Accepts optional numeric parameter for how many frames to move up." do |inc_str|
|
6
6
|
inc = inc_str.nil? ? 1 : inc_str.to_i
|
7
7
|
|
@@ -13,12 +13,17 @@ module PryStackExplorer
|
|
13
13
|
# FrameManager took over.
|
14
14
|
attr_reader :prior_binding
|
15
15
|
|
16
|
+
# @return [Array] The backtrace of the Pry instance before the
|
17
|
+
# FrameManager took over.
|
18
|
+
attr_reader :prior_backtrace
|
19
|
+
|
16
20
|
def initialize(bindings, _pry_)
|
17
21
|
self.bindings = bindings
|
18
22
|
self.binding_index = 0
|
19
23
|
@pry = _pry_
|
20
24
|
@user = {}
|
21
25
|
@prior_binding = _pry_.binding_stack.last
|
26
|
+
@prior_backtrace = _pry_.backtrace
|
22
27
|
end
|
23
28
|
|
24
29
|
# Iterate over all frames
|
data/pry-stack_explorer.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.2.
|
4
|
+
s.name = %q{pry-stack_explorer}
|
5
|
+
s.version = "0.2.9pre2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.files = [
|
13
|
-
s.homepage =
|
14
|
-
s.require_paths = [
|
8
|
+
s.authors = [%q{John Mair (banisterfiend)}]
|
9
|
+
s.date = %q{2012-01-14}
|
10
|
+
s.description = %q{Walk the stack in a Pry session}
|
11
|
+
s.email = %q{jrmair@gmail.com}
|
12
|
+
s.files = [%q{.gemtest}, %q{.gitignore}, %q{.travis.yml}, %q{.yardopts}, %q{CHANGELOG}, %q{Gemfile}, %q{LICENSE}, %q{README.md}, %q{Rakefile}, %q{examples/example.rb}, %q{examples/example2.rb}, %q{lib/pry-stack_explorer.rb}, %q{lib/pry-stack_explorer/commands.rb}, %q{lib/pry-stack_explorer/frame_manager.rb}, %q{lib/pry-stack_explorer/version.rb}, %q{pry-stack_explorer.gemspec}, %q{test/helper.rb}, %q{test/test_commands.rb}, %q{test/test_frame_manager.rb}, %q{test/test_stack_explorer.rb}, %q{tester.rb}]
|
13
|
+
s.homepage = %q{https://github.com/banister}
|
14
|
+
s.require_paths = [%q{lib}]
|
15
15
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
16
|
-
s.rubygems_version =
|
17
|
-
s.summary =
|
18
|
-
s.test_files = [
|
16
|
+
s.rubygems_version = %q{1.8.6}
|
17
|
+
s.summary = %q{Walk the stack in a Pry session}
|
18
|
+
s.test_files = [%q{test/helper.rb}, %q{test/test_commands.rb}, %q{test/test_frame_manager.rb}, %q{test/test_stack_explorer.rb}]
|
19
19
|
|
20
20
|
if s.respond_to? :specification_version then
|
21
21
|
s.specification_version = 3
|
data/test/test_commands.rb
CHANGED
data/test/test_stack_explorer.rb
CHANGED
@@ -130,6 +130,13 @@ describe PryStackExplorer do
|
|
130
130
|
PryStackExplorer.frame_manager(_pry_).prior_binding.should == b
|
131
131
|
end
|
132
132
|
|
133
|
+
it 'should save prior backtrace in FrameManager instance' do
|
134
|
+
_pry_ = Pry.new
|
135
|
+
_pry_.backtrace = ["my backtrace"]
|
136
|
+
PryStackExplorer.create_and_push_frame_manager(@bindings, _pry_)
|
137
|
+
PryStackExplorer.frame_manager(_pry_).prior_backtrace.should == _pry_.backtrace
|
138
|
+
end
|
139
|
+
|
133
140
|
it "should create and push multiple FrameManagers" do
|
134
141
|
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
135
142
|
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
@@ -193,6 +200,31 @@ describe PryStackExplorer do
|
|
193
200
|
PE.frame_managers(@pry_instance).count.should == 0
|
194
201
|
PE.frame_managers(p2).count.should == 1
|
195
202
|
end
|
203
|
+
|
204
|
+
it "should remove key when no frames remaining for Pry instance" do
|
205
|
+
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
206
|
+
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
207
|
+
PE.pop_frame_manager(@pry_instance)
|
208
|
+
PE.pop_frame_manager(@pry_instance)
|
209
|
+
PE.frame_hash.has_key?(@pry_instance).should == false
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "_pry_.backtrace" do
|
213
|
+
it "should restore backtrace when frame is popped" do
|
214
|
+
p1 = Pry.new
|
215
|
+
bindings = [binding, binding]
|
216
|
+
p1.backtrace = "my backtrace1"
|
217
|
+
PE.create_and_push_frame_manager(bindings, p1)
|
218
|
+
p1.backtrace = "my backtrace2"
|
219
|
+
PE.create_and_push_frame_manager(bindings, p1)
|
220
|
+
p1.backtrace = "my backtrace3"
|
221
|
+
|
222
|
+
PE.pop_frame_manager(p1)
|
223
|
+
p1.backtrace.should == "my backtrace2"
|
224
|
+
PE.pop_frame_manager(p1)
|
225
|
+
p1.backtrace.should == "my backtrace1"
|
226
|
+
end
|
227
|
+
end
|
196
228
|
end
|
197
229
|
|
198
230
|
describe "PryStackExplorer.clear_frame_managers" do
|
@@ -200,18 +232,41 @@ describe PryStackExplorer do
|
|
200
232
|
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
201
233
|
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
202
234
|
PE.clear_frame_managers(@pry_instance)
|
203
|
-
PE.
|
235
|
+
PE.frame_hash.has_key?(@pry_instance).should == false
|
204
236
|
end
|
205
237
|
|
206
|
-
it "should clear all FrameManagers for a Pry instance" do
|
238
|
+
it "should clear all FrameManagers for a Pry instance but leave others untouched" do
|
207
239
|
p2 = Pry.new
|
208
240
|
bindings = [binding, binding]
|
209
241
|
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
210
242
|
PE.create_and_push_frame_manager(bindings, p2)
|
211
243
|
PE.clear_frame_managers(@pry_instance)
|
212
244
|
PE.frame_managers(p2).count.should == 1
|
213
|
-
PE.
|
245
|
+
PE.frame_hash.has_key?(@pry_instance).should == false
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should remove key" do
|
249
|
+
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
250
|
+
PE.create_and_push_frame_manager(@bindings, @pry_instance)
|
251
|
+
PE.clear_frame_managers(@pry_instance)
|
252
|
+
PE.frame_hash.has_key?(@pry_instance).should == false
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "_pry_.backtrace" do
|
256
|
+
it "should restore backtrace to initial one when frame managers are cleared" do
|
257
|
+
p1 = Pry.new
|
258
|
+
bindings = [binding, binding]
|
259
|
+
p1.backtrace = "my backtrace1"
|
260
|
+
PE.create_and_push_frame_manager(bindings, p1)
|
261
|
+
p1.backtrace = "my backtrace2"
|
262
|
+
PE.create_and_push_frame_manager(bindings, p1)
|
263
|
+
p1.backtrace = "my backtrace3"
|
264
|
+
|
265
|
+
PE.clear_frame_managers(p1)
|
266
|
+
p1.backtrace.should == "my backtrace1"
|
267
|
+
end
|
214
268
|
end
|
269
|
+
|
215
270
|
end
|
216
271
|
end
|
217
272
|
end
|
metadata
CHANGED
@@ -1,70 +1,66 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-stack_explorer
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.9pre2
|
4
5
|
prerelease: 5
|
5
|
-
version: 0.2.9pre1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- John Mair (banisterfiend)
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: binding_of_caller
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70272934305720 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 0.6.1
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: pry
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *70272934305720
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: pry
|
27
|
+
requirement: &70272934305080 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
34
32
|
version: 0.9.8pre4
|
35
33
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: bacon
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
version_requirements: *70272934305080
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bacon
|
38
|
+
requirement: &70272934304360 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
40
|
+
requirements:
|
43
41
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
42
|
+
- !ruby/object:Gem::Version
|
45
43
|
version: 1.1.0
|
46
44
|
type: :development
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rake
|
50
45
|
prerelease: false
|
51
|
-
|
46
|
+
version_requirements: *70272934304360
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70272934303560 !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
|
-
requirements:
|
51
|
+
requirements:
|
54
52
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
57
55
|
type: :development
|
58
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70272934303560
|
59
58
|
description: Walk the stack in a Pry session
|
60
59
|
email: jrmair@gmail.com
|
61
60
|
executables: []
|
62
|
-
|
63
61
|
extensions: []
|
64
|
-
|
65
62
|
extra_rdoc_files: []
|
66
|
-
|
67
|
-
files:
|
63
|
+
files:
|
68
64
|
- .gemtest
|
69
65
|
- .gitignore
|
70
66
|
- .travis.yml
|
@@ -88,32 +84,29 @@ files:
|
|
88
84
|
- tester.rb
|
89
85
|
homepage: https://github.com/banister
|
90
86
|
licenses: []
|
91
|
-
|
92
87
|
post_install_message:
|
93
88
|
rdoc_options: []
|
94
|
-
|
95
|
-
require_paths:
|
89
|
+
require_paths:
|
96
90
|
- lib
|
97
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
92
|
none: false
|
99
|
-
requirements:
|
100
|
-
- -
|
101
|
-
- !ruby/object:Gem::Version
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
102
96
|
version: 1.9.2
|
103
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
98
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
99
|
+
requirements:
|
100
|
+
- - ! '>'
|
101
|
+
- !ruby/object:Gem::Version
|
108
102
|
version: 1.3.1
|
109
103
|
requirements: []
|
110
|
-
|
111
104
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.8.
|
105
|
+
rubygems_version: 1.8.6
|
113
106
|
signing_key:
|
114
107
|
specification_version: 3
|
115
108
|
summary: Walk the stack in a Pry session
|
116
|
-
test_files:
|
109
|
+
test_files:
|
117
110
|
- test/helper.rb
|
118
111
|
- test/test_commands.rb
|
119
112
|
- test/test_frame_manager.rb
|