pry-stack_explorer 0.2.3pre1 → 0.2.5pre1

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/Rakefile CHANGED
@@ -22,7 +22,7 @@ def apply_spec_defaults(s)
22
22
  s.email = 'jrmair@gmail.com'
23
23
  s.description = s.summary
24
24
  s.require_path = 'lib'
25
- s.add_dependency("binding_of_caller","~>0.5.0")
25
+ s.add_dependency("binding_of_caller","~>0.6.0")
26
26
  s.add_development_dependency("bacon","~>1.1.0")
27
27
  s.homepage = "https://github.com/banister"
28
28
  s.files = Dir["lib/**/*.rb", "test/*.rb", "CHANGELOG", "README.md", "Rakefile"]
@@ -33,6 +33,11 @@ task :pry do
33
33
  exec("pry -I#{direc}/lib/ -r #{direc}/lib/#{PROJECT_NAME}")
34
34
  end
35
35
 
36
+ desc "Run example"
37
+ task :example do
38
+ sh "ruby -I#{direc}/lib/ #{direc}/examples/example.rb "
39
+ end
40
+
36
41
  desc "run tests"
37
42
  task :test do
38
43
  sh "bacon -Itest -rubygems -a"
@@ -1,3 +1,3 @@
1
1
  module PryStackExplorer
2
- VERSION = "0.2.3pre1"
2
+ VERSION = "0.2.5pre1"
3
3
  end
@@ -7,12 +7,17 @@ require "binding_of_caller"
7
7
 
8
8
  module PryStackExplorer
9
9
 
10
- def self.frame_manager
11
- Thread.current[:__pry_frame_manager__]
10
+ def self.add_frame_manager(bindings, _pry_)
11
+ Thread.current[:__pry_frame_managers__] ||= {}
12
+ Thread.current[:__pry_frame_managers__][_pry_] = FrameManager.new(bindings, _pry_)
12
13
  end
13
14
 
14
- def self.frame_manager=(obj)
15
- Thread.current[:__pry_frame_manager__] = obj
15
+ def self.delete_frame_manager(_pry_)
16
+ Thread.current[:__pry_frame_managers__].delete(_pry_)
17
+ end
18
+
19
+ def self.frame_manager(_pry_)
20
+ Thread.current[:__pry_frame_managers__][_pry_]
16
21
  end
17
22
 
18
23
  def self.bindings_equal?(b1, b2)
@@ -26,9 +31,10 @@ module PryStackExplorer
26
31
  attr_reader :binding_index
27
32
  attr_accessor :bindings
28
33
 
29
- def initialize(bindings)
34
+ def initialize(bindings, _pry_)
30
35
  @bindings = bindings
31
36
  @binding_index = 0
37
+ @pry = _pry_
32
38
  end
33
39
 
34
40
  def convert_from_one_index(n)
@@ -40,18 +46,43 @@ module PryStackExplorer
40
46
  end
41
47
  private :convert_from_one_index
42
48
 
43
- def change_binding_to(index, pry_instance)
49
+ def signature(b)
50
+ if b.eval('__method__')
51
+ "#{closure_type} in #{b.eval('self').class}##{b.eval('__method__')}"
52
+ else
53
+ if b.eval('self').is_a?(Module)
54
+ "#{closure_type} in <class:#{b.eval('self')}>"
55
+ end
56
+ end
57
+ end
58
+
59
+ def binding_info_for(b)
60
+ b_self = b.eval('self')
61
+ b_method = b.eval('__method__')
62
+
63
+ if b_method && b_method != :__binding__ && b_method != :__binding_impl__
64
+ b_method.to_s
65
+ elsif b_self.instance_of?(Module)
66
+ "<module:#{b_self}>"
67
+ elsif b_self.instance_of?(Class)
68
+ "<class:#{b_self}>"
69
+ else
70
+ "<main>"
71
+ end
72
+ end
73
+
74
+ def change_binding_to(index)
44
75
  index = convert_from_one_index(index)
45
76
 
46
77
  if index > bindings.size - 1
47
- pry_instance.output.puts "Warning: At top of stack, cannot go further!"
78
+ @pry.output.puts "Warning: At top of stack, cannot go further!"
48
79
  elsif index < 0
49
- pry_instance.output.puts "Warning: At bottom of stack, cannot go further!"
80
+ @pry.output.puts "Warning: At bottom of stack, cannot go further!"
50
81
  else
51
82
  @binding_index = index
52
- pry_instance.binding_stack[-1] = bindings[binding_index]
83
+ @pry.binding_stack[-1] = bindings[binding_index]
53
84
 
54
- pry_instance.run_command "whereami"
85
+ @pry.run_command "whereami"
55
86
  end
56
87
  end
57
88
  end
@@ -60,41 +91,89 @@ module PryStackExplorer
60
91
  command "up", "Go up to the caller's context" do |inc_str|
61
92
  inc = inc_str.nil? ? 1 : inc_str.to_i
62
93
 
63
- if !PryStackExplorer.frame_manager
94
+ if !PryStackExplorer.frame_manager(_pry_)
64
95
  output.puts "Nowhere to go!"
65
96
  else
66
- binding_index = PryStackExplorer.frame_manager.binding_index
67
- PryStackExplorer.frame_manager.change_binding_to binding_index + inc + 1, _pry_
97
+ binding_index = PryStackExplorer.frame_manager(_pry_).binding_index
98
+ PryStackExplorer.frame_manager(_pry_).change_binding_to binding_index + inc + 1
68
99
  end
69
100
  end
70
101
 
71
102
  command "down", "Go down to the callee's context." do |inc_str|
72
103
  inc = inc_str.nil? ? 1 : inc_str.to_i
73
104
 
74
- if !PryStackExplorer.frame_manager
105
+ if !PryStackExplorer.frame_manager(_pry_)
75
106
  output.puts "Nowhere to go!"
76
107
  else
77
- binding_index = PryStackExplorer.frame_manager.binding_index
78
- PryStackExplorer.frame_manager.change_binding_to binding_index - inc + 1, _pry_
108
+ binding_index = PryStackExplorer.frame_manager(_pry_).binding_index
109
+ PryStackExplorer.frame_manager(_pry_).change_binding_to binding_index - inc + 1
110
+ end
111
+ end
112
+
113
+ command "show-stack", "Show all frames" do |*args|
114
+ opts = parse_options!(args) do |opt|
115
+ opt.banner unindent <<-USAGE
116
+ Usage: show-stack [OPTIONS]
117
+ Show all accessible stack frames.
118
+ e.g: show-stack -v
119
+ USAGE
120
+
121
+ opt.on :v, :verbose, "Include extra information."
122
+ end
123
+
124
+ if !PryStackExplorer.frame_manager(_pry_)
125
+ output.puts "No caller stack available!"
126
+ else
127
+ output.puts "\n#{text.bold('Showing all accessible frames in stack:')}\n--\n"
128
+
129
+ PryStackExplorer.frame_manager(_pry_).bindings.each_with_index do |b, i|
130
+ meth = b.eval('__method__')
131
+ b_self = b.eval('self')
132
+
133
+ desc = b.frame_description ? "#{text.bold('Description:')} #{b.frame_description}".ljust(40) :
134
+ "#{text.bold('Description:')} #{PryStackExplorer.frame_manager(_pry_).binding_info_for(b)}".ljust(40)
135
+ sig = meth ? "#{text.bold('Signature:')} #{Pry::Method.new(b_self.method(meth)).signature}".ljust(40) : "".ljust(32)
136
+ type = b.frame_type ? "#{text.bold('Type:')} #{b.frame_type}".ljust(20) : "".ljust(20)
137
+ slf = "#{text.bold('Self:')} #{b_self}".ljust(20)
138
+ path = "#{text.bold("@ File:")} #{b.eval('__FILE__')}:#{b.eval('__LINE__')}"
139
+
140
+ info = "##{i + 1} #{desc} #{sig} #{slf if opts[:v]} #{type \
141
+ if opts[:v]} #{path if opts[:v]}"
142
+ if i == PryStackExplorer.frame_manager(_pry_).binding_index
143
+
144
+ output.puts "=> #{info}"
145
+ else
146
+ output.puts " #{info}"
147
+ end
148
+ end
79
149
  end
80
150
  end
81
151
 
82
152
  command "frame", "Switch to a particular frame." do |frame_num|
83
- PryStackExplorer.frame_manager.change_binding_to frame_num.to_i, _pry_
153
+ if !PryStackExplorer.frame_manager(_pry_)
154
+ output.puts "nowhere to go!"
155
+ else
156
+ PryStackExplorer.frame_manager(_pry_).change_binding_to frame_num.to_i
157
+ end
84
158
  end
85
159
 
86
160
  command "frame-type", "Display current frame type." do
87
- bindex = PryStackExplorer.frame_manager.binding_index
88
- output.puts PryStackExplorer.frame_manager.bindings[bindex].frame_type
161
+ output.puts _pry_.binding_stack.last.frame_type
89
162
  end
90
163
  end
91
164
  end
92
165
 
93
- Pry.config.hooks.add_hook(:when_started, :save_caller_bindings) do |target|
94
- if binding.of_caller(5).eval('__method__') == :pry
95
- drop_number = 6
166
+ Pry.config.hooks.add_hook(:after_session, :delete_frame_manager) do |_, _, _pry_|
167
+ PryStackExplorer.delete_frame_manager(_pry_)
168
+ end
169
+
170
+ Pry.config.hooks.add_hook(:when_started, :save_caller_bindings) do |binding_stack, _pry_|
171
+ target = binding_stack.last
172
+
173
+ if binding.of_caller(6).eval('__method__') == :pry
174
+ drop_number = 7
96
175
  else
97
- drop_number = 5
176
+ drop_number = 6
98
177
  end
99
178
 
100
179
  bindings = binding.callers.drop(drop_number)
@@ -107,7 +186,8 @@ Pry.config.hooks.add_hook(:when_started, :save_caller_bindings) do |target|
107
186
  bindings.unshift(target)
108
187
  end
109
188
 
110
- PryStackExplorer.frame_manager = PryStackExplorer::FrameManager.new(bindings)
189
+ binding_stack.replace([bindings.first])
190
+ PryStackExplorer.add_frame_manager(bindings, _pry_)
111
191
  end
112
192
 
113
193
  Pry.config.commands.import PryStackExplorer::StackCommands
@@ -115,12 +195,12 @@ Pry.config.commands.import PryStackExplorer::StackCommands
115
195
  # monkey-patch the whereami command to show some frame information,
116
196
  # useful for navigating stack.
117
197
  Pry.config.commands.before_command("whereami") do |num|
118
- if PryStackExplorer.frame_manager
119
- bindings = PryStackExplorer.frame_manager.bindings
120
- binding_index = PryStackExplorer.frame_manager.binding_index
198
+ if PryStackExplorer.frame_manager(_pry_)
199
+ bindings = PryStackExplorer.frame_manager(_pry_).bindings
200
+ binding_index = PryStackExplorer.frame_manager(_pry_).binding_index
121
201
 
122
202
  output.puts "\n"
123
203
  output.puts "#{Pry::Helpers::Text.bold('Frame number:')} #{binding_index + 1}/#{bindings.size}"
124
- output.puts "#{Pry::Helpers::Text.bold('Frame type:')} #{bindings[binding_index].frame_type}" rescue nil
204
+ output.puts "#{Pry::Helpers::Text.bold('Frame type:')} #{bindings[binding_index].frame_type}" if bindings[binding_index].frame_type
125
205
  end
126
206
  end
metadata CHANGED
@@ -1,44 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pry-stack_explorer
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.3pre1
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease: 5
5
+ version: 0.2.5pre1
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
- date: 2011-11-25 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2011-12-06 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: binding_of_caller
16
- requirement: &70114011666420 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
20
+ requirements:
19
21
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 0.5.0
22
+ - !ruby/object:Gem::Version
23
+ version: 0.6.0
22
24
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70114011666420
25
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
26
27
  name: bacon
27
- requirement: &70114011665900 !ruby/object:Gem::Requirement
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
28
30
  none: false
29
- requirements:
31
+ requirements:
30
32
  - - ~>
31
- - !ruby/object:Gem::Version
33
+ - !ruby/object:Gem::Version
32
34
  version: 1.1.0
33
35
  type: :development
34
- prerelease: false
35
- version_requirements: *70114011665900
36
+ version_requirements: *id002
36
37
  description: Walk the stack in a Pry session
37
38
  email: jrmair@gmail.com
38
39
  executables: []
40
+
39
41
  extensions: []
42
+
40
43
  extra_rdoc_files: []
41
- files:
44
+
45
+ files:
42
46
  - lib/pry-stack_explorer/version.rb
43
47
  - lib/pry-stack_explorer.rb
44
48
  - test/test.rb
@@ -47,26 +51,30 @@ files:
47
51
  - Rakefile
48
52
  homepage: https://github.com/banister
49
53
  licenses: []
54
+
50
55
  post_install_message:
51
56
  rdoc_options: []
52
- require_paths:
57
+
58
+ require_paths:
53
59
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
60
+ required_ruby_version: !ruby/object:Gem::Requirement
55
61
  none: false
56
- requirements:
57
- - - ! '>='
58
- - !ruby/object:Gem::Version
59
- version: '0'
60
- required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
67
  none: false
62
- requirements:
63
- - - ! '>'
64
- - !ruby/object:Gem::Version
68
+ requirements:
69
+ - - ">"
70
+ - !ruby/object:Gem::Version
65
71
  version: 1.3.1
66
72
  requirements: []
73
+
67
74
  rubyforge_project:
68
- rubygems_version: 1.8.10
75
+ rubygems_version: 1.8.11
69
76
  signing_key:
70
77
  specification_version: 3
71
78
  summary: Walk the stack in a Pry session
72
79
  test_files: []
80
+