pry-moves 0.1.10 → 0.1.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59d8dcb4799c37a91cfa512e77b630ec5db8f4bb13e03c16c0d446fd18c6b671
4
- data.tar.gz: 55ce87ad4d54f91a3d132ca29e208a5291d596ef443c5f9cb4263b24a7cf8ddd
3
+ metadata.gz: 4eb609ecd661432f7eca70446fc26fad89320d8ddedda45a037dc8c6c76ab92e
4
+ data.tar.gz: 9b371f36ba08d7132892d7a3f680aa64401efcc15cd9a0f91eaa27f2c7599456
5
5
  SHA512:
6
- metadata.gz: e82f7cae3194b3e3246066c940474c98a68e12f20efdb2552bbef97746935468fc864bac5aead31f14405a7976385b0cc315a0292c01c41667a55252022077a4
7
- data.tar.gz: 5ce34a40af72680b9d28441ce67e9da713104c73c8cf9d6b2c82860ad7e452551fbb35b11a0226e36a6a624483cea8c177a0a68681af8fcab1450054386bb922
6
+ metadata.gz: 5d7ee71f4ffb8d919cfd69f8915aac4361b941ca216ff01fdb78ad28c7580130707989ec8e54f1b64217cdae111fec54d62f86c826f29feac01b5fca4bef3982
7
+ data.tar.gz: e85691ac7f3efd68cdff8efe9010e49c87922a2346dfc4f9bb72be9ce0083a0d2227d80233a8a8e4f8053a35fcbbd41b5c29306bf02045a70a8e5bc6acda40a9
data/README.md CHANGED
@@ -17,6 +17,7 @@ _An execution control add-on for [Pry][pry]._
17
17
  * `f` - **finish** execution of current frame (block or method) and stop at next line on higher level
18
18
  * `iterate` - go to next iteration of current block
19
19
  * `c` - **continue**
20
+ * `g 10` - **goto** line 10
20
21
  * `bt` - show latest 5 lines from backtrace
21
22
  * `bt 10` - latest 10 lines
22
23
  * `bt full` - full backtrace
@@ -26,6 +27,7 @@ _An execution control add-on for [Pry][pry]._
26
27
  * `up +` - move up, including vapid frames (block callers, hidden frames)
27
28
  * `up pattern` - move up till first frame which method name or file position in format `folder/script.rb:12` matches regexp pattern
28
29
  * `debug some_method(some_param)` - call `some_method(some_param)` and interactively step into it. This way you can virtually "step back" by executing previous pieces of code from current method
30
+ * `.method` or `123` or `:hash_key` - Continue traversing of last object in history. E.g. `orders` will list array, then `3` will enter `orders[3]`, then `.price` will enter `orders[3].price`
29
31
  * `watch variable` - display variable's value on each step
30
32
  * `!` - exit
31
33
 
@@ -136,7 +138,7 @@ bundle exec rspec
136
138
  * Ivo Anjo ([@ivoanjo](https://github.com/ivoanjo))
137
139
 
138
140
  Patches and bug reports are welcome. Just send a [pull request][pullrequests] or
139
- file an [issue][issues]. [Project changelog][changelog].
141
+ file an [issue][issues].
140
142
 
141
143
  ## Acknowledgments
142
144
 
@@ -2,9 +2,11 @@ require 'pry' unless defined? Pry
2
2
 
3
3
  require 'pry-moves/version'
4
4
  require 'pry-moves/trace_commands'
5
+ require 'pry-moves/traced_method'
5
6
  require 'pry-moves/tracer'
6
7
  require 'pry-moves/pry_ext'
7
8
  require 'pry-moves/commands'
9
+ require 'pry-moves/traversing'
8
10
  require 'pry-moves/pry_wrapper'
9
11
  require 'pry-moves/backtrace'
10
12
  require 'pry-moves/watch'
@@ -61,9 +61,10 @@ class PryMoves::Backtrace
61
61
  def build_result(stack, result)
62
62
  current_object = nil
63
63
  stack.each do |binding|
64
- obj = binding.eval 'self'
65
- if current_object != obj
66
- result << "#{format_obj(obj)}:"
64
+ obj, debug_snapshot = binding.eval '[self, (debug_snapshot rescue nil)]'
65
+ # Comparison of objects directly may raise exception
66
+ if current_object.object_id != obj.object_id
67
+ result << "#{debug_snapshot || format_obj(obj)}:"
67
68
  current_object = obj
68
69
  end
69
70
 
@@ -81,8 +82,7 @@ class PryMoves::Backtrace
81
82
  end
82
83
 
83
84
  def build_line(binding)
84
- file = "#{binding.eval('__FILE__')}"
85
- file.gsub!( /^#{Rails.root.to_s}/, '') if defined? Rails
85
+ file = PryMoves::Helpers.shorten_path "#{binding.eval('__FILE__')}"
86
86
 
87
87
  signature = PryMoves::Helpers.method_signature binding
88
88
  signature = ":#{binding.frame_type}" if !signature or signature.length < 1
@@ -5,14 +5,17 @@ module PryMoves
5
5
  block_command 'step', 'Step execution into the next line or method.' do |param|
6
6
  breakout_navigation :step, param
7
7
  end
8
+ alias_command 's', 'step'
8
9
 
9
10
  block_command 'finish', 'Finish - xule tut neponyatnogo' do |param|
10
11
  breakout_navigation :finish, param
11
12
  end
13
+ alias_command 'f', 'finish'
12
14
 
13
15
  block_command 'next', 'Execute the next line stepping into blocks' do |param|
14
16
  breakout_navigation :next, param
15
17
  end
18
+ alias_command 'n', 'next'
16
19
 
17
20
  block_command 'nn', 'Execute the next line skipping blocks' do |param|
18
21
  breakout_navigation :next, 'blockless'
@@ -22,15 +25,16 @@ module PryMoves
22
25
  breakout_navigation :iterate, param
23
26
  end
24
27
 
28
+ block_command 'goto', 'goto line' do |param|
29
+ breakout_navigation :goto, param
30
+ end
31
+ alias_command 'g', 'goto'
32
+
25
33
  block_command 'continue', 'Continue program execution and end the Pry session' do
26
34
  check_file_context
27
35
  run 'exit-all'
28
36
  end
29
-
30
37
  alias_command 'c', 'continue'
31
- alias_command 's', 'step'
32
- alias_command 'n', 'next'
33
- alias_command 'f', 'finish'
34
38
 
35
39
  block_command 'watch', 'Display value of expression on every move' do |param|
36
40
  PryMoves::Watch.instance.process_cmd param, target
@@ -47,4 +47,10 @@ module PryMoves::Helpers
47
47
  end
48
48
  end
49
49
 
50
+ PATH_TRASH = defined?(Rails) ? Rails.root.to_s : Dir.pwd
51
+
52
+ def shorten_path(path)
53
+ path.gsub( /^#{PATH_TRASH}\//, '')
54
+ end
55
+
50
56
  end
@@ -19,6 +19,9 @@ module PryMoves::Painter
19
19
  Pry::ColorPrinter.pp obj, colored_str
20
20
  end
21
21
  colored_str.chomp
22
+ rescue => e
23
+ "Inspect error: #{e}\n" +
24
+ "#{e.backtrace.first(3).join("\n")}"
22
25
  end
23
26
 
24
27
  end
@@ -57,7 +57,7 @@ Pry::Command::Whereami.class_eval do
57
57
 
58
58
  def build_output
59
59
  lines = []
60
- lines << "#{text.bold('From:')} #{location}"
60
+ lines << "#{text.bold('From:')} #{PryMoves::Helpers.shorten_path location}"
61
61
  lines << PryMoves::Watch.instance.output(target) unless PryMoves::Watch.instance.empty?
62
62
  lines << ''
63
63
  lines << "#{code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted}"
@@ -102,4 +102,8 @@ module PryMoves::TraceCommands
102
102
  )
103
103
  end
104
104
 
105
+ def trace_goto(event, file, line, method, binding_)
106
+ event == 'line' && @goto_line == line and @method[:file] == file
107
+ end
108
+
105
109
  end
@@ -0,0 +1,61 @@
1
+ module PryMoves::TracedMethod
2
+
3
+ private
4
+
5
+ def set_traced_method(binding)
6
+ @recursion_level = 0
7
+ @c_stack_level = 0
8
+ @stay_at_frame = nil # reset tracked digest
9
+
10
+ method = find_method_definition binding
11
+ if method
12
+ source = method.source_location
13
+ set_method({
14
+ file: source[0],
15
+ start: source[1],
16
+ name: method.name,
17
+ end: (source[1] + method.source.count("\n") - 1)
18
+ })
19
+ else
20
+ set_method({file: binding.eval('__FILE__')})
21
+ end
22
+ end
23
+
24
+ def find_method_definition(binding)
25
+ method_name, obj, line, file =
26
+ binding.eval '[__method__, self, __LINE__, __FILE__]'
27
+ return unless method_name
28
+
29
+ method = obj.method(method_name)
30
+ return method if method.source_location[0] == file
31
+
32
+ # If found file was different - search definition at superclasses:
33
+ obj.class.ancestors.each do |cls|
34
+ if cls.instance_methods(false).include? method_name
35
+ method = cls.instance_method method_name
36
+ return method if method.source_location[0] == file
37
+ end
38
+ end
39
+
40
+ pry_puts "⚠️ Unable to find definition for method #{method_name} in #{obj}"
41
+
42
+ nil
43
+ end
44
+
45
+ def set_method(method)
46
+ #puts "set_traced_method #{method}"
47
+ @method = method
48
+ end
49
+
50
+ def within_current_method?(file, line)
51
+ @method[:file] == file and (
52
+ @method[:start].nil? or
53
+ line.between?(@method[:start], @method[:end])
54
+ )
55
+ end
56
+
57
+ def before_end?(line)
58
+ @method[:end] and line < @method[:end]
59
+ end
60
+
61
+ end
@@ -1,9 +1,12 @@
1
+ require 'digest'
2
+
1
3
  require 'pry' unless defined? Pry
2
4
 
3
5
  module PryMoves
4
6
  class Tracer
5
7
 
6
8
  include PryMoves::TraceCommands
9
+ include PryMoves::TracedMethod
7
10
 
8
11
  def initialize(command, pry_start_options)
9
12
  @command = command
@@ -41,6 +44,8 @@ class Tracer
41
44
  when :iterate
42
45
  @iteration_start_line = binding_.eval('__LINE__')
43
46
  @caller_digest = frame_digest(binding_)
47
+ when :goto
48
+ @goto_line = @command[:param].to_i
44
49
  end
45
50
 
46
51
  start_tracing
@@ -69,37 +74,13 @@ class Tracer
69
74
  Thread.current : Kernel
70
75
  end
71
76
 
72
- def set_traced_method(binding)
73
- @recursion_level = 0
74
- @c_stack_level = 0
75
- @stay_at_frame = nil # reset tracked digest
76
-
77
- method = binding.eval 'method(__method__) if __method__'
78
- if method
79
- source = method.source_location
80
- set_method({
81
- file: source[0],
82
- start: source[1],
83
- name: method.name,
84
- end: (source[1] + method.source.count("\n") - 1)
85
- })
86
- else
87
- set_method({file: binding.eval('__FILE__')})
88
- end
89
- end
90
-
91
- def set_method(method)
92
- #puts "set_traced_method #{method}"
93
- @method = method
94
- end
95
-
96
77
  def frame_digest(binding_)
97
78
  #puts "frame_digest for: #{binding_.eval '__callee__'}"
98
79
  Digest::MD5.hexdigest binding_.instance_variable_get('@iseq').disasm
99
80
  end
100
81
 
101
82
  def tracing_func(event, file, line, id, binding_, klass)
102
- #printf ": %8s %s:%-2d %10s %8s rec:#{@recursion_level} st:#{@c_stack_level}\n", event, file, line, id, klass
83
+ # printf ": %8s %s:%-2d %10s %8s rec:#{@recursion_level} st:#{@c_stack_level}\n", event, file, line, id, klass
103
84
 
104
85
  # Ignore traces inside pry-moves code
105
86
  return if file && TRACE_IGNORE_FILES.include?(File.expand_path(file))
@@ -145,16 +126,6 @@ class Tracer
145
126
  puts "#{id} #{@method[:start]} > #{line} > #{@method[:end]}"
146
127
  end
147
128
 
148
- def within_current_method?(file, line)
149
- @method[:file] == file and (
150
- @method[:start].nil? or
151
- line.between?(@method[:start], @method[:end])
152
- )
153
- end
154
-
155
- def before_end?(line)
156
- @method[:end] and line < @method[:end]
157
- end
158
129
 
159
130
  def pry_puts(text)
160
131
  @command[:pry].output.puts text
@@ -164,6 +135,6 @@ class Tracer
164
135
  @pry_start_options[:exit_from_method] = true
165
136
  true
166
137
  end
167
-
138
+
139
+ end
168
140
  end
169
- end
@@ -0,0 +1,69 @@
1
+ module PryMoves
2
+
3
+ class Traversing < Pry::ClassCommand
4
+
5
+ group 'Input and Output'
6
+ description "Continue traversing of last object in history."
7
+
8
+ banner <<-'BANNER'
9
+ Usage: .method | 123 | :hash_key
10
+
11
+ Continue traversing of last object in history
12
+
13
+ E.g. `orders` will list array, then `3` will enter `orders[3]`, then `.price` will enter `orders[3].price`
14
+ BANNER
15
+
16
+ def process(cmd)
17
+ last_cmd = Pry.history.to_a[-1]
18
+ cmd = "#{last_cmd}#{wrap_command(cmd)}"
19
+ _pry_.pager.page " > #{cmd}\n"
20
+ _pry_.eval cmd
21
+ end
22
+
23
+ private
24
+
25
+
26
+ end
27
+
28
+ class Method < Traversing
29
+ match(/^\.(.+)$/)
30
+
31
+ def wrap_command(cmd)
32
+ ".#{cmd}"
33
+ end
34
+ end
35
+
36
+ class ArrayIndex < Traversing
37
+ match(/^(\d+)$/)
38
+
39
+ def wrap_command(cmd)
40
+ "[#{cmd}]"
41
+ end
42
+ end
43
+
44
+ class HashKey < Traversing
45
+ match(/^(:\w+)$/)
46
+
47
+ def wrap_command(cmd)
48
+ "[#{cmd}]"
49
+ end
50
+ end
51
+
52
+ Pry::Commands.add_command(PryMoves::Method)
53
+ Pry::Commands.add_command(PryMoves::ArrayIndex)
54
+ Pry::Commands.add_command(PryMoves::HashKey)
55
+
56
+ end
57
+
58
+ Pry::History.class_eval do
59
+
60
+ EXCLUDE = [PryMoves::Method, PryMoves::ArrayIndex, PryMoves::HashKey]
61
+
62
+ def <<(line)
63
+ return if EXCLUDE.any? do |cls|
64
+ line.match(cls.match)
65
+ end
66
+ push line
67
+ end
68
+
69
+ end
@@ -1,3 +1,3 @@
1
1
  module PryMoves
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.12'
3
3
  end
@@ -0,0 +1,2 @@
1
+ Forked and modified copy of pry-stack_explorer v0.4.9.
2
+ Latest upstream merged: v0.4.9.3
@@ -108,7 +108,7 @@ module PryStackExplorer
108
108
  (b1.eval('self').equal?(b2.eval('self'))) &&
109
109
  (b1.eval('__method__') == b2.eval('__method__')) &&
110
110
  (b1.eval('local_variables').map { |v| b1.eval("#{v}") }.equal?(
111
- b2.eval('local_variables').map { |v| b2.eval("#{v}") }))
111
+ b2.eval('local_variables').map { |v| b2.eval("#{v}") }))
112
112
  end
113
113
  end
114
114
  end
@@ -117,6 +117,7 @@ Pry.config.hooks.add_hook(:after_session, :delete_frame_manager) do |_, _, _pry_
117
117
  PryStackExplorer.clear_frame_managers(_pry_)
118
118
  end
119
119
 
120
+ # Can be moved to start_with_pry_nav to isolate from other use cases of Pry
120
121
  Pry.config.hooks.add_hook(:when_started, :save_caller_bindings, PryStackExplorer::WhenStartedHook.new)
121
122
 
122
123
  # Import the StackExplorer commands
@@ -124,14 +125,14 @@ Pry.config.commands.import PryStackExplorer::Commands
124
125
 
125
126
  # monkey-patch the whereami command to show some frame information,
126
127
  # useful for navigating stack.
127
- Pry.config.commands.before_command("whereami") do |num|
128
+ Pry.config.hooks.add_hook(:before_whereami, :stack_explorer) do
128
129
  if PryStackExplorer.frame_manager(_pry_) && !internal_binding?(target)
129
130
  bindings = PryStackExplorer.frame_manager(_pry_).bindings
130
131
  binding_index = PryStackExplorer.frame_manager(_pry_).binding_index
131
132
 
132
133
  info = "#{Pry::Helpers::Text.bold('Frame:')} "+
133
- "#{binding_index}/#{bindings.size - 1} "+
134
- "#{bindings[binding_index].frame_type}"
134
+ "#{binding_index}/#{bindings.size - 1} "+
135
+ "#{bindings[binding_index].frame_type}"
135
136
 
136
137
  output.puts "\n"
137
138
  output.puts info
@@ -12,6 +12,11 @@ module PryStackExplorer
12
12
  end
13
13
 
14
14
  def call(target, options, _pry_)
15
+ start_from_console = target.eval('__callee__').nil? &&
16
+ target.eval('__FILE__') == '<main>' &&
17
+ target.eval('__LINE__') == 0
18
+ return if start_from_console
19
+
15
20
  target ||= _pry_.binding_stack.first if _pry_
16
21
  options = {
17
22
  :call_stack => true,
@@ -23,14 +28,18 @@ module PryStackExplorer
23
28
  if options[:call_stack].is_a?(Array)
24
29
  bindings = options[:call_stack]
25
30
 
26
- if !valid_call_stack?(bindings)
31
+ unless valid_call_stack?(bindings)
27
32
  raise ArgumentError, ":call_stack must be an array of bindings"
28
33
  end
29
34
  else
30
35
  bindings = caller_bindings(target)
36
+ initial_frame = bindings.find do |b|
37
+ not b.local_variable_defined?(:vapid_frame)
38
+ end
39
+ options[:initial_frame] = bindings.index initial_frame
31
40
  end
32
41
 
33
- PryStackExplorer.create_and_push_frame_manager bindings, _pry_, :initial_frame => options[:initial_frame]
42
+ PryStackExplorer.create_and_push_frame_manager bindings, _pry_, initial_frame: options[:initial_frame]
34
43
  end
35
44
 
36
45
  private
@@ -1,23 +1,21 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- pry-moves (0.1.9)
4
+ pry-moves (0.1.11)
5
5
  binding_of_caller (~> 0.7)
6
- pry (>= 0.10.4, < 0.12.0)
6
+ pry (>= 0.10.4, < 1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  binding_of_caller (0.8.0)
12
12
  debug_inspector (>= 0.0.1)
13
- coderay (1.1.1)
13
+ coderay (1.1.2)
14
14
  debug_inspector (0.0.3)
15
- method_source (0.8.2)
16
- pry (0.10.4)
15
+ method_source (0.9.2)
16
+ pry (0.12.2)
17
17
  coderay (~> 1.1.0)
18
- method_source (~> 0.8.1)
19
- slop (~> 3.4)
20
- slop (3.6.0)
18
+ method_source (~> 0.9.0)
21
19
 
22
20
  PLATFORMS
23
21
  ruby
@@ -1,7 +1,8 @@
1
+ require 'pry'
1
2
  require 'pry-moves'
2
3
  require './tracer.rb'
3
4
  require './playground.rb'
4
-
5
+ require './class_a.rb'
5
6
 
6
7
  def debug?(something)
7
8
  puts something
@@ -11,14 +12,39 @@ def sentence
11
12
  :opa
12
13
  end
13
14
 
15
+ class B < A
16
+
17
+ def me
18
+ super
19
+ puts :ok
20
+ "rule#{1}"
21
+ "rule#{1}"
22
+ end
23
+
24
+ end
14
25
 
15
26
  def aaa
16
- puts :ok
17
- "rule#{1}"
18
- binding.pry if debug? "rule#{1}"
19
- puts :ok
27
+ bbb
28
+ end
20
29
 
30
+ def bbb
31
+ hide_from_stack = true
32
+ ccc
21
33
  end
22
34
 
23
- binding.pry
35
+ def ccc
36
+ hide_from_stack = true
37
+ binding.pry
38
+ end
39
+
40
+ x = 34
41
+ aaa
42
+
43
+ x = 35
44
+ x+=1
45
+ x+=1
46
+ x+=1
47
+ x+=1
48
+
49
+ B.new.me
24
50
  aaa
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  # Dependencies
21
21
  gem.required_ruby_version = '>= 1.8.7'
22
- gem.add_runtime_dependency 'pry', '>= 0.10.4', '< 0.12.0'
22
+ gem.add_runtime_dependency 'pry', '>= 0.10.4', '< 1'
23
23
  gem.add_runtime_dependency 'binding_of_caller', '~> 0.7'
24
24
  gem.add_development_dependency 'pry-remote', '~> 0.1.6'
25
25
  end
@@ -0,0 +1,2 @@
1
+ gem build pry-moves.gemspec
2
+ gem push pry-moves-`ruby -e 'require "./lib/pry-moves/version.rb"; puts PryMoves::VERSION'`.gem
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-moves
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - garmoshka-mo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-28 00:00:00.000000000 Z
11
+ date: 2019-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 0.10.4
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 0.12.0
22
+ version: '1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 0.10.4
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.12.0
32
+ version: '1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: binding_of_caller
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -82,9 +82,12 @@ files:
82
82
  - lib/pry-moves/pry_remote_ext.rb
83
83
  - lib/pry-moves/pry_wrapper.rb
84
84
  - lib/pry-moves/trace_commands.rb
85
+ - lib/pry-moves/traced_method.rb
85
86
  - lib/pry-moves/tracer.rb
87
+ - lib/pry-moves/traversing.rb
86
88
  - lib/pry-moves/version.rb
87
89
  - lib/pry-moves/watch.rb
90
+ - lib/pry-stack_explorer/VERSION
88
91
  - lib/pry-stack_explorer/commands.rb
89
92
  - lib/pry-stack_explorer/frame_manager.rb
90
93
  - lib/pry-stack_explorer/pry-stack_explorer.rb
@@ -100,6 +103,7 @@ files:
100
103
  - playground/threads.rb
101
104
  - playground/tracer.rb
102
105
  - pry-moves.gemspec
106
+ - publish.sh
103
107
  - spec/backtrace_spec.rb
104
108
  - spec/blocks_spec.rb
105
109
  - spec/commands_spec.rb