pry-stack_explorer 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7458ddda997e35095c5ebe7330a0ff651c4e424fdf0abbc6178fc8d7ae8367cb
4
- data.tar.gz: ef6c275c07566ae94163be5df2f3358b671c4692789432a8dcd0e864891ee018
3
+ metadata.gz: 53b80cf3c06d7bdfaec826bed2ad1963a7bc69331d656e73b84d00e97a500197
4
+ data.tar.gz: 1942e6ad4fd0b43279d860aa06b2ca354b64eac8b713d426996b9a93a12f48d9
5
5
  SHA512:
6
- metadata.gz: c5f740846b70146461babd122cc2b67f4b97fce0697ffca96a8ec24be9abca029427a5500bc2e4b8d211fd574b31e719a8a97d9b9201b52c22c04a7137cb8a39
7
- data.tar.gz: 80bdd4a91d73943051f83847ee7933763c06a3c089e50ed3e7b28d595a691a693bf1c4b5b11022bde82f7658922cc5bc3e81a025803deafad0ff7997135fc220
6
+ metadata.gz: 2c51eb15eb17f9edff667c93fbead5a7ffe7fa1c4cd3114e516a2057e37ab728e8436f5123908d0fac07a823b2a61fbcc50072429fc8f5081c3c85be5bcaf1d2
7
+ data.tar.gz: 24dc58f1bfda481a2eddee4e294c953e7ead4bee736da3f07bc142f237e7fcb8b41da9a1bd39517ae53fb34a892b7cd9f2faae3240c2e382031b09ba31eced21
data/README.md CHANGED
@@ -31,7 +31,7 @@ Commands:
31
31
 
32
32
  In Gemfile:
33
33
  ```rb
34
- gem 'pry-stack_explorer', '~> 0.5.0'
34
+ gem 'pry-stack_explorer', '~> 0.6.0'
35
35
  ```
36
36
 
37
37
  ```
@@ -43,7 +43,7 @@ gem install pry-stack_explorer
43
43
 
44
44
 
45
45
  ### Branches and compatible Ruby versions
46
- * v0.5: Ruby 2.6+, Pry 0.13+
46
+ * v0.5, v0.6: Ruby 2.6+, Pry 0.13+
47
47
  * v0.4.11+: Ruby 2.5, Pry 0.12+ (branch `0-4` – end-of-life in March 2021)
48
48
  * v0.4.9.3: Older versions (unsupported)
49
49
 
@@ -247,6 +247,7 @@ module PryStackExplorer
247
247
  opt.on :H, :head, "Display the first N stack frames (defaults to 10).", :optional_argument => true, :as => Integer, :default => 10
248
248
  opt.on :T, :tail, "Display the last N stack frames (defaults to 10).", :optional_argument => true, :as => Integer, :default => 10
249
249
  opt.on :c, :current, "Display N frames either side of current frame (default to 5).", :optional_argument => true, :as => Integer, :default => 5
250
+ opt.on :a, :app, "Display application frames only", optional_argument: true
250
251
  end
251
252
 
252
253
  def memoized_info(index, b, verbose)
@@ -290,26 +291,72 @@ module PryStackExplorer
290
291
  private :selected_stack_frames
291
292
 
292
293
  def process
293
- if !frame_manager
294
- output.puts "No caller stack available!"
294
+ return no_stack_available! unless frame_manager
295
+
296
+ title = "Showing all accessible frames in stack (#{frame_manager.bindings.size} in total):"
297
+
298
+ content = [
299
+ bold(title),
300
+ "---",
301
+ make_stack_lines
302
+ ].join("\n")
303
+
304
+ stagger_output content
305
+ end
306
+
307
+ private
308
+
309
+ def make_stack_lines
310
+ frames_with_indices.map do |b, i|
311
+ make_stack_line(b, i, (i == frame_manager.binding_index))
312
+ end.join("\n")
313
+ end
314
+
315
+ def frames_with_indices
316
+ if opts.present?(:app) && defined?(ActiveSupport::BacktraceCleaner)
317
+ app_frames
295
318
  else
296
- content = ""
297
- content << "\n#{bold("Showing all accessible frames in stack (#{frame_manager.bindings.size} in total):")}\n--\n"
298
-
299
- base_frame_index, frames = selected_stack_frames
300
- frames.each_with_index do |b, index|
301
- i = index + base_frame_index
302
- if i == frame_manager.binding_index
303
- content << "=> ##{i} #{memoized_info(i, b, opts[:v])}\n"
304
- else
305
- content << " ##{i} #{memoized_info(i, b, opts[:v])}\n"
306
- end
307
- end
319
+ offset_frames
320
+ end
321
+ end
322
+
323
+ # "=> #0 method_name <Class#method(...)>"
324
+ def make_stack_line(b, i, active)
325
+ arw = active ? "=>" : " "
326
+
327
+ "#{arw} ##{i} #{memoized_info(i, b, opts[:v])}"
328
+ end
308
329
 
309
- stagger_output content
330
+ def offset_frames
331
+ base_frame_index, frames = selected_stack_frames
332
+
333
+ frames.each_with_index.map do |frame, index|
334
+ [frame, index + base_frame_index]
310
335
  end
311
336
  end
312
337
 
338
+ def no_stack_available!
339
+ output.puts "No caller stack available!"
340
+ end
341
+
342
+ LOCATION_LAMBDA = ->(_binding){ _binding.source_location[0] }
343
+
344
+ def app_frames
345
+ locations = frame_manager.bindings.map(&LOCATION_LAMBDA)
346
+ filtered = backtrace_cleaner.clean(locations)
347
+
348
+ frame_manager.bindings
349
+ .each_with_index
350
+ .map
351
+ .select do |_binding, _index|
352
+ LOCATION_LAMBDA.call(_binding).in?(filtered)
353
+ end
354
+ end
355
+
356
+ # also see Rails::BacktraceCleaner
357
+ def backtrace_cleaner
358
+ @backtrace_cleaner ||= ActiveSupport::BacktraceCleaner.new
359
+ end
313
360
  end
314
361
 
315
362
  alias_command "show-stack", "stack"
@@ -1,3 +1,3 @@
1
1
  module PryStackExplorer
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-stack_explorer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair (banisterfiend)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-31 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -83,7 +83,10 @@ files:
83
83
  homepage: https://github.com/pry/pry-stack_explorer
84
84
  licenses:
85
85
  - MIT
86
- metadata: {}
86
+ metadata:
87
+ bug_tracker_uri: https://github.com/pry/pry-stack_explorer/issues
88
+ source_code_uri: https://github.com/pry/pry-stack_explorer
89
+ changelog_uri: https://github.com/pry/pry-stack_explorer/blob/master/CHANGELOG
87
90
  post_install_message:
88
91
  rdoc_options: []
89
92
  require_paths: