pry-stack_explorer 0.3.5 → 0.3.6

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.
@@ -3,14 +3,21 @@ require 'pry'
3
3
  module PryStackExplorer
4
4
  module FrameHelpers
5
5
  private
6
+
7
+ # @return [PryStackExplorer::FrameManager] The active frame manager for
8
+ # the current `Pry` instance.
6
9
  def frame_manager
7
10
  PryStackExplorer.frame_manager(_pry_)
8
11
  end
9
12
 
13
+ # @return [Array<PryStackExplorer::FrameManager>] All the frame
14
+ # managers for the current `Pry` instance.
10
15
  def frame_managers
11
16
  PryStackExplorer.frame_managers(_pry_)
12
17
  end
13
18
 
19
+ # @return [Boolean] Whether there is a context to return to once
20
+ # the current `frame_manager` is popped.
14
21
  def prior_context_exists?
15
22
  frame_managers.count > 1 || frame_manager.prior_binding
16
23
  end
@@ -59,6 +66,8 @@ module PryStackExplorer
59
66
  end
60
67
  end
61
68
 
69
+ # @param [Pry::Method] meth_obj The method object.
70
+ # @return [String] Signature for the method object in Class#method format.
62
71
  def signature_with_owner(meth_obj)
63
72
  if !meth_obj.undefined?
64
73
  args = meth_obj.parameters.inject([]) do |arr, (type, name)|
@@ -136,6 +145,8 @@ module PryStackExplorer
136
145
 
137
146
  def options(opt)
138
147
  opt.on :v, :verbose, "Include extra information."
148
+ opt.on :H, :head, "Display the first N stack frames (defaults to 10).", :optional => true, :as => Integer, :default => 10
149
+ opt.on :T, :tail, "Display the last N stack frames (defaults to 10).", :optional => true, :as => Integer, :default => 10
139
150
  end
140
151
 
141
152
  def memoized_info(index, b, verbose)
@@ -148,6 +159,28 @@ module PryStackExplorer
148
159
  end
149
160
  end
150
161
 
162
+ private :memoized_info
163
+
164
+ # @return [Array<Fixnum, Array<Binding>>] Return tuple of
165
+ # base_frame_index and the array of frames.
166
+ def selected_stack_frames
167
+ if opts.present?(:head)
168
+ [0, frame_manager.bindings[0..(opts[:head] - 1)]]
169
+ elsif opts.present?(:tail)
170
+ tail = opts[:tail]
171
+ if tail > frame_manager.bindings.size
172
+ tail = frame_manager.bindings.size
173
+ end
174
+
175
+ base_frame_index = frame_manager.bindings.size - tail
176
+ [base_frame_index, frame_manager.bindings[base_frame_index..-1]]
177
+ else
178
+ [0, frame_manager.bindings]
179
+ end
180
+ end
181
+
182
+ private :selected_stack_frames
183
+
151
184
  def process
152
185
  if !frame_manager
153
186
  output.puts "No caller stack available!"
@@ -155,7 +188,9 @@ module PryStackExplorer
155
188
  content = ""
156
189
  content << "\n#{text.bold("Showing all accessible frames in stack (#{frame_manager.bindings.size} in total):")}\n--\n"
157
190
 
158
- frame_manager.each_with_index do |b, i|
191
+ base_frame_index, frames = selected_stack_frames
192
+ frames.each_with_index do |b, index|
193
+ i = index + base_frame_index
159
194
  if i == frame_manager.binding_index
160
195
  content << "=> ##{i} #{memoized_info(i, b, opts[:v])}\n"
161
196
  else
@@ -169,7 +204,6 @@ module PryStackExplorer
169
204
  end
170
205
  end
171
206
 
172
-
173
207
  create_command "frame", "Switch to a particular frame. Accepts numeric parameter for the target frame to switch to (use with show-stack). Negative frame numbers allowed." do
174
208
  include FrameHelpers
175
209
 
@@ -1,3 +1,3 @@
1
1
  module PryStackExplorer
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
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.5"
5
+ s.version = "0.3.6"
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)"]
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.5
5
+ version: 0.3.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Mair (banisterfiend)