pry-moves 1.0.11 → 1.0.13

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: 055037ce750443ea5d107432df9127da420d404d5567d9f4ec1a4501a2452385
4
- data.tar.gz: a08f1bfca1142318f4028e09b640a1f587afd2de23449772588cb70ed826f94d
3
+ metadata.gz: 54b617db559dc0394f447095883171d67be49bbddd46bffb6d65206efd6a7d4b
4
+ data.tar.gz: aff84108e38f6be7e651ac0363f83046af91b287856773a8e5944b1d45e218f1
5
5
  SHA512:
6
- metadata.gz: 451a2f4c4807038fb862b14a4a00fcd6615b4e6350bd666a6fce81662963890d33139d5cf2358887de08b3f5feef1f5795f861b4166d2676d9f58802942b0539
7
- data.tar.gz: 61a04809ebf60788253fd40211a706f12bd4c425af71742a27a8368536e6c4a657c510134689cf66cb09bbd5c46e13a2b50cf6295a0bdf71c49d78711b61c621
6
+ metadata.gz: 97c48fd3a44a337062e934de38faa1bce273f29ef81d6e7d3a957f38318deb1c512bc816ba1d12ab0b2c24893fd3c61453b4cf7b0f718b0bd198ff1e304f55bb
7
+ data.tar.gz: 2de12cf6e43a8f6e488acec5db74b8745b2b7ef27c6c3b526e6835ea5b89c2f013a1f180202056c401ac147878038d103ea62d81b0fbb3b4a0d3c85486c9db46
data/Gemfile.lock CHANGED
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-moves (1.0.10)
4
+ pry-moves (1.0.12)
5
5
  awesome_print (>= 1.8.0)
6
6
  binding_of_caller (~> 0.7)
7
7
  colorize (~> 0.8)
8
8
  diffy (~> 3.4.0)
9
9
  pry (>= 0.10.4, < 0.13)
10
- pry-coolline (~> 0.2.5)
11
10
 
12
11
  GEM
13
12
  remote: https://rubygems.org/
@@ -17,17 +16,13 @@ GEM
17
16
  debug_inspector (>= 0.0.1)
18
17
  coderay (1.1.2)
19
18
  colorize (0.8.1)
20
- coolline (0.5.0)
21
- unicode_utils (~> 1.4)
22
- debug_inspector (1.1.0)
19
+ debug_inspector (1.2.0)
23
20
  diff-lcs (1.3)
24
21
  diffy (3.4.2)
25
22
  method_source (0.9.0)
26
23
  pry (0.11.3)
27
24
  coderay (~> 1.1.0)
28
25
  method_source (~> 0.9.0)
29
- pry-coolline (0.2.5)
30
- coolline (~> 0.5)
31
26
  pry-remote (0.1.8)
32
27
  pry (~> 0.9)
33
28
  slop (~> 3.0)
@@ -45,7 +40,6 @@ GEM
45
40
  rspec-support (~> 3.8.0)
46
41
  rspec-support (3.8.0)
47
42
  slop (3.6.0)
48
- unicode_utils (1.4.0)
49
43
 
50
44
  PLATFORMS
51
45
  ruby
data/README.md CHANGED
@@ -38,13 +38,21 @@ Documentation for latest version. For [v0.1.12 see documentation here](https://g
38
38
  * `.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`
39
39
  * `watch variable` - display variable's value on each step
40
40
  * `diff expression` - display difference between saved expression (on first run) and expression 2
41
+ * `profile [timeout]` - profile time-consuming code and infinite loops/recursion
41
42
  * `off` - Turn off debugging (don't stop on breakpoints)
42
43
  * `@` - restart and reload scripts (in app/ & spec/ by default), reload rake tasks. Configurable.
43
44
  * `#` - exit with code 3, can be wrapped in bash script to fully reload ruby scripts
44
45
  * `!` - exit
45
46
 
46
47
  Variable & methods names takes precedence over commands.
47
- So if you have variable named `step`, to execute command `step` type `cmd step` or command's alias, e.g. `s`
48
+ So if you have variable named `step`, to execute command `step` type `cmd step` or command's alias, e.g. `s`
49
+
50
+ Custom commands:
51
+ ```ruby
52
+ PryMoves.custom_command "say" do |args, output|
53
+ output.puts "Pry says: #{args}"
54
+ end
55
+ ```
48
56
 
49
57
  ## Examples
50
58
 
@@ -0,0 +1,34 @@
1
+ class PryMoves::Profile < PryMoves::TraceCommand
2
+
3
+ def init(binding_)
4
+ @start_line = binding_.eval('__LINE__')
5
+ @profiling_start_at = Time.now
6
+ @timeout = (@command[:param]&.to_i || 3).seconds
7
+ end
8
+
9
+ def trace(event, file, line, method, binding_)
10
+ return unless file.start_with? PryMoves.project_root
11
+
12
+ if Time.now - @profiling_start_at > @timeout
13
+ PryMoves.messages << "Profiling timeout: #{@timeout} seconds"
14
+ return true
15
+ end
16
+
17
+ stop = false
18
+ place = "#{method} @ #{file}:#{line}"
19
+ if @last_place != place
20
+ if @last_start_at
21
+ took = Time.now - @last_start_at
22
+ if took > 0.1
23
+ PryMoves.messages << "#{@last_place} took #{took} seconds"
24
+ stop = true
25
+ end
26
+ end
27
+ @last_place = place
28
+ @last_start_at = Time.now
29
+ end
30
+
31
+ stop
32
+ end
33
+
34
+ end
@@ -81,6 +81,9 @@ class TraceCommand
81
81
  elsif event == "return" and traced_method?(file, line, method, binding_)
82
82
  @call_depth -= 1
83
83
  end
84
+ rescue => err
85
+ puts err.backtrace.reverse
86
+ puts "PryMoves Tracing error: #{err}".red
84
87
  end
85
88
 
86
89
  def traced_method?(file, line, method, binding_)
@@ -82,6 +82,8 @@ Pry::History.class_eval do
82
82
  line.match(cls.match)
83
83
  end
84
84
  push line
85
+ rescue => error
86
+ puts "Pry::History << error: #{error}"
85
87
  end
86
88
 
87
89
  end
@@ -44,8 +44,12 @@ class CodeReloader
44
44
  end
45
45
 
46
46
  def rails_path_exceptions
47
- Rails.autoloaders.main.ignore.map do
48
- _1.to_s.gsub /^#{Rails.root.to_s}\//, ""
47
+ if defined?(Rails)
48
+ Rails.autoloaders.main.ignore.map do
49
+ _1.to_s.gsub /^#{Rails.root.to_s}\//, ""
50
+ end
51
+ else
52
+ []
49
53
  end
50
54
  rescue
51
55
  []
@@ -42,7 +42,7 @@ module PryMoves
42
42
  alias_command 'g', 'goto'
43
43
 
44
44
  block_command 'continue', 'Continue program execution and end the Pry session' do
45
- check_file_context
45
+ _check_file_context
46
46
  run 'exit-all'
47
47
  end
48
48
  alias_command 'c', 'continue'
@@ -66,6 +66,10 @@ module PryMoves
66
66
  breakout_navigation :debug, cmd
67
67
  end
68
68
 
69
+ block_command 'profile', '' do |param|
70
+ breakout_navigation :profile, param
71
+ end
72
+
69
73
  block_command 'off', '' do
70
74
  PryMoves.switch if PryMoves.stop_on_breakpoints?
71
75
  run 'continue'
@@ -103,7 +107,7 @@ module PryMoves
103
107
  def breakout_navigation(action, param)
104
108
  return if PryMoves::Vars.var_precedence action, target
105
109
 
106
- check_file_context
110
+ _check_file_context
107
111
  _pry_.binding_stack.clear # Clear the binding stack.
108
112
  throw :breakout_nav, { # Break out of the REPL loop and
109
113
  action: action, # signal the tracer.
@@ -113,7 +117,7 @@ module PryMoves
113
117
  end
114
118
 
115
119
  # Ensures that a command is executed in a local file context.
116
- def check_file_context
120
+ def _check_file_context
117
121
  unless PryMoves.check_file_context(target)
118
122
  raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'
119
123
  end
@@ -1,10 +1,11 @@
1
1
  class PryMoves::ErrorWithData < StandardError
2
2
 
3
- attr_reader :metadata
3
+ attr_reader :data
4
+ alias metadata data
4
5
 
5
- def initialize(msg, metadata)
6
+ def initialize(msg, data)
6
7
  super msg
7
- @metadata = metadata
8
+ @data = data
8
9
  end
9
-
10
- end
10
+
11
+ end
@@ -57,12 +57,9 @@ class PryMoves::Formatter
57
57
  str.length > 50 ? "#{str.first 50}..." : str
58
58
  end
59
59
 
60
- def path_trash
61
- @path_trash ||= defined?(Rails) ? Rails.root.to_s : Dir.pwd
62
- end
63
-
64
60
  def shorten_path(path)
65
- path = path.gsub( /^#{path_trash}\//, '')
61
+ project_root = PryMoves.project_root
62
+ path = path.gsub( /^#{project_root}\//, '')
66
63
  PryMoves::Backtrace.trim_path ?
67
64
  File.basename(path, ".*") : path
68
65
  end
@@ -112,7 +112,7 @@ Pry::Command::Whereami.class_eval do
112
112
  end
113
113
 
114
114
  def location
115
- defined?(Rails) ? @file.gsub(Rails.root.to_s, '') : @file
115
+ @file
116
116
  end
117
117
  end
118
118
 
@@ -141,4 +141,4 @@ Pry::Output.class_eval do
141
141
  pry_moves_origin_for_puts *args
142
142
  end
143
143
 
144
- end if defined? Pry::Output
144
+ end if defined? Pry::Output
@@ -45,6 +45,7 @@ class PryWrapper
45
45
  end
46
46
 
47
47
  ensure
48
+ PryMoves.trigger :after_debug, nil
48
49
  PryMoves.is_open = false
49
50
  Pry.config.marker = "=>"
50
51
  end
@@ -93,4 +94,4 @@ class PryWrapper
93
94
  end
94
95
 
95
96
  end
96
- end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module PryMoves
2
- VERSION = '1.0.11'
2
+ VERSION = '1.0.13'
3
3
  end
data/lib/pry-moves.rb CHANGED
@@ -93,7 +93,7 @@ module PryMoves
93
93
  return if at and self.debug_called_times != at
94
94
  return if from and self.debug_called_times < from
95
95
  if message
96
- PryMoves.messages << (message.is_a?(String) ? message : message.ai)
96
+ PryMoves.messages << format_debug_object(message)
97
97
  end
98
98
  binding.pry options
99
99
  PryMoves.re_execution
@@ -127,9 +127,16 @@ module PryMoves
127
127
 
128
128
  MAX_MESSAGE_CHARS = 520
129
129
  def format_debug_object obj
130
- output = obj.ai rescue "#{obj.class} #{obj}"
131
- output.length > MAX_MESSAGE_CHARS ?
132
- output[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : output
130
+ result = case obj
131
+ when String
132
+ obj
133
+ when Hash
134
+ result = obj.map {"#{_1}:#{_2}"}.join " "
135
+ result if result.length < 100
136
+ end
137
+ result ||= obj.ai rescue "#{obj.class} #{obj}"
138
+ result.length > MAX_MESSAGE_CHARS ?
139
+ result[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : result
133
140
  end
134
141
 
135
142
  def debug_error(message, debug_object=nil)
@@ -159,6 +166,18 @@ module PryMoves
159
166
  Pry.commands.block_command command, "", &block
160
167
  end
161
168
 
169
+ def custom_command command, &block
170
+ cls = Pry::Commands.create_command command, "", :shellwords => false do; end
171
+ cls.define_method(:process_block) do |args, output|
172
+ block.call args, output
173
+ end
174
+ cls.class_eval do
175
+ def process
176
+ process_block args, output
177
+ end
178
+ end
179
+ end
180
+
162
181
  def locked?
163
182
  semaphore.locked?
164
183
  end
@@ -185,6 +204,8 @@ module PryMoves
185
204
 
186
205
  def trigger(event, context)
187
206
  triggers[event].each {|t| t.call context}
207
+ rescue => err
208
+ puts "PryMoves :#{event} Trigger error: #{err}".red
188
209
  end
189
210
 
190
211
  def triggers
@@ -193,12 +214,16 @@ module PryMoves
193
214
  end
194
215
  end
195
216
 
196
- TRIGGERS = [:each_new_run, :restart]
217
+ TRIGGERS = [:each_new_run, :restart, :after_debug]
197
218
  def on(trigger, &block)
198
219
  error "Invalid trigger, possible triggers: #{TRIGGERS}", trigger unless TRIGGERS.include? trigger
199
220
  triggers[trigger] << block
200
221
  end
201
222
 
223
+ def project_root
224
+ @project_root ||= defined?(Rails) ? Rails.root.to_s : Dir.pwd
225
+ end
226
+
202
227
  # Reference to currently running pry-remote server. Used by the tracer.
203
228
  attr_accessor :current_remote_server
204
229
  end
data/lib/requires.rb CHANGED
@@ -31,6 +31,7 @@ require 'commands/iterate'
31
31
  require 'commands/next'
32
32
  require 'commands/next_breakpoint'
33
33
  require 'commands/step'
34
+ require 'commands/profile'
34
35
 
35
36
  require 'pry-stack_explorer/pry-stack_explorer'
36
37
  require 'sugar/debug_sugar'
@@ -26,7 +26,7 @@ def shit!(err = 'Oh, shit!', debug_object = nil)
26
26
  message = "💩 #{err.is_a?(String) ? err : err.message}"
27
27
  raise err unless PryMoves.stop_on_breakpoints?
28
28
  lines = [message.red]
29
- lines.prepend debug_object.ai if debug_object
29
+ lines.prepend PryMoves.format_debug_object(debug_object) if debug_object
30
30
  PryMoves.debug_error lines.join("\n")
31
31
  nil
32
32
  end
data/pry-moves.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
20
20
  # Dependencies
21
21
  gem.required_ruby_version = '>= 1.8.7', '< 3'
22
22
  gem.add_runtime_dependency 'pry', '>= 0.10.4', '< 0.13'
23
- gem.add_runtime_dependency 'pry-coolline', '~> 0.2.5'
23
+ # gem.add_runtime_dependency 'pry-coolline', '~> 0.2.5'
24
24
  gem.add_runtime_dependency 'binding_of_caller', '~> 0.7'
25
25
  gem.add_runtime_dependency 'colorize', '~> 0.8'
26
26
  gem.add_runtime_dependency 'awesome_print', '>= 1.8.0'
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: 1.0.11
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - garmoshka-mo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-15 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -30,20 +30,6 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0.13'
33
- - !ruby/object:Gem::Dependency
34
- name: pry-coolline
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: 0.2.5
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: 0.2.5
47
33
  - !ruby/object:Gem::Dependency
48
34
  name: binding_of_caller
49
35
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +122,7 @@ files:
136
122
  - lib/commands/iterate.rb
137
123
  - lib/commands/next.rb
138
124
  - lib/commands/next_breakpoint.rb
125
+ - lib/commands/profile.rb
139
126
  - lib/commands/step.rb
140
127
  - lib/commands/trace_command.rb
141
128
  - lib/commands/trace_helpers.rb