pry-moves 1.0.12 → 1.0.14
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -2
- data/lib/commands/profile.rb +7 -0
- data/lib/pry-moves/add_suffix.rb +2 -0
- data/lib/pry-moves/pry_ext.rb +11 -8
- data/lib/pry-moves/pry_wrapper.rb +2 -1
- data/lib/pry-moves/version.rb +1 -1
- data/lib/pry-moves.rb +35 -7
- data/lib/sugar/debug_sugar.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82685576fb9e632b60556d82f67459719b6e202008915e8220c84cbbacd4f65d
|
4
|
+
data.tar.gz: 5d0025eb1080c6c4e22510b4996116318eafca80720991274980f32c15bfe9f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79b6cbe65d7eec6a06211941082925439555d84538979ee838457ac67f0e057227e88919c9f99ddb6570a5c8e07083b4e39a47055786804d198b5316b1436fd5
|
7
|
+
data.tar.gz: ad42f69cde5275f2f533900ec878765f03fe3c57019e5fafd391088324802fd66ba2b61364d0990b8ae5bfbc6b7aaa7c9bec79600577f8a86ec859ecc6faa361
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,14 +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` - profile
|
41
|
+
* `profile [timeout]` - profile time-consuming code and infinite loops/recursion
|
42
42
|
* `off` - Turn off debugging (don't stop on breakpoints)
|
43
43
|
* `@` - restart and reload scripts (in app/ & spec/ by default), reload rake tasks. Configurable.
|
44
44
|
* `#` - exit with code 3, can be wrapped in bash script to fully reload ruby scripts
|
45
45
|
* `!` - exit
|
46
46
|
|
47
47
|
Variable & methods names takes precedence over commands.
|
48
|
-
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
|
+
```
|
49
56
|
|
50
57
|
## Examples
|
51
58
|
|
data/lib/commands/profile.rb
CHANGED
@@ -2,11 +2,18 @@ class PryMoves::Profile < PryMoves::TraceCommand
|
|
2
2
|
|
3
3
|
def init(binding_)
|
4
4
|
@start_line = binding_.eval('__LINE__')
|
5
|
+
@profiling_start_at = Time.now
|
6
|
+
@timeout = (@command[:param]&.to_i || 3).seconds
|
5
7
|
end
|
6
8
|
|
7
9
|
def trace(event, file, line, method, binding_)
|
8
10
|
return unless file.start_with? PryMoves.project_root
|
9
11
|
|
12
|
+
if Time.now - @profiling_start_at > @timeout
|
13
|
+
PryMoves.messages << "Profiling timeout: #{@timeout} seconds"
|
14
|
+
return true
|
15
|
+
end
|
16
|
+
|
10
17
|
stop = false
|
11
18
|
place = "#{method} @ #{file}:#{line}"
|
12
19
|
if @last_place != place
|
data/lib/pry-moves/add_suffix.rb
CHANGED
data/lib/pry-moves/pry_ext.rb
CHANGED
@@ -84,14 +84,17 @@ Pry::Command::Whereami.class_eval do
|
|
84
84
|
def build_output
|
85
85
|
lines = ['']
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
87
|
+
unless PryMoves.hide_code
|
88
|
+
formatter = PryMoves::Formatter.new
|
89
|
+
prefix = Thread.current[:pry_moves_debug] ? "👾 " : ""
|
90
|
+
# lines << "🍱 #{PryMoves.test_example}" if PryMoves.test_example
|
91
|
+
lines << "🦆 step_in_everywhere" if PryMoves.step_in_everywhere
|
92
|
+
lines << "#{prefix}#{formatter.shorten_path location}:#{@line} #{me}"
|
93
|
+
lines << " ." + formatter.method_signature(target)
|
94
|
+
lines << ''
|
95
|
+
lines << "#{code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted}"
|
96
|
+
end
|
97
|
+
PryMoves.hide_code = false
|
95
98
|
|
96
99
|
lines << PryMoves::Watch.instance.output(target) unless PryMoves::Watch.instance.empty?
|
97
100
|
lines.concat(PryMoves.messages.map do |message|
|
data/lib/pry-moves/version.rb
CHANGED
data/lib/pry-moves.rb
CHANGED
@@ -9,7 +9,7 @@ module PryMoves
|
|
9
9
|
attr_accessor :is_open, :trace, :stack_tips,
|
10
10
|
:stop_on_breakpoints, :dont_print_errors,
|
11
11
|
:test_example, :launched_specs_examples,
|
12
|
-
:debug_called_times, :step_in_everywhere
|
12
|
+
:debug_called_times, :step_in_everywhere, :hide_code
|
13
13
|
|
14
14
|
def loop
|
15
15
|
Kernel.loop do
|
@@ -84,7 +84,7 @@ module PryMoves
|
|
84
84
|
self.step_in_everywhere = false
|
85
85
|
end
|
86
86
|
|
87
|
-
def debug(message = nil, data: nil, at: nil, from: nil, options:
|
87
|
+
def debug(message = nil, data: nil, at: nil, from: nil, options: {})
|
88
88
|
pry_moves_stack_end = true
|
89
89
|
message ||= data
|
90
90
|
PryMoves.re_execution
|
@@ -93,8 +93,9 @@ 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
|
96
|
+
PryMoves.messages << format_debug_object(message)
|
97
97
|
end
|
98
|
+
self.hide_code = true if data
|
98
99
|
binding.pry options
|
99
100
|
PryMoves.re_execution
|
100
101
|
end
|
@@ -127,9 +128,16 @@ module PryMoves
|
|
127
128
|
|
128
129
|
MAX_MESSAGE_CHARS = 520
|
129
130
|
def format_debug_object obj
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
result = case obj
|
132
|
+
when String
|
133
|
+
obj
|
134
|
+
when Hash
|
135
|
+
result = obj.map {"#{_1}:#{_2}"}.join " "
|
136
|
+
result if result.length < 100
|
137
|
+
end
|
138
|
+
result ||= obj.ai rescue "#{obj.class} #{obj}"
|
139
|
+
result.length > MAX_MESSAGE_CHARS ?
|
140
|
+
result[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : result
|
133
141
|
end
|
134
142
|
|
135
143
|
def debug_error(message, debug_object=nil)
|
@@ -159,6 +167,18 @@ module PryMoves
|
|
159
167
|
Pry.commands.block_command command, "", &block
|
160
168
|
end
|
161
169
|
|
170
|
+
def custom_command command, &block
|
171
|
+
cls = Pry::Commands.create_command command, "", :shellwords => false do; end
|
172
|
+
cls.define_method(:process_block) do |args, output|
|
173
|
+
block.call args, output
|
174
|
+
end
|
175
|
+
cls.class_eval do
|
176
|
+
def process
|
177
|
+
process_block args, output
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
162
182
|
def locked?
|
163
183
|
semaphore.locked?
|
164
184
|
end
|
@@ -185,6 +205,8 @@ module PryMoves
|
|
185
205
|
|
186
206
|
def trigger(event, context)
|
187
207
|
triggers[event].each {|t| t.call context}
|
208
|
+
rescue => err
|
209
|
+
puts "PryMoves :#{event} Trigger error: #{err}".red
|
188
210
|
end
|
189
211
|
|
190
212
|
def triggers
|
@@ -193,9 +215,15 @@ module PryMoves
|
|
193
215
|
end
|
194
216
|
end
|
195
217
|
|
196
|
-
|
218
|
+
# Alos: PryMoves.on(each_new_run: [:skip_on_init])
|
219
|
+
TRIGGERS = [:each_new_run, :restart, :after_debug]
|
197
220
|
def on(trigger, &block)
|
198
221
|
error "Invalid trigger, possible triggers: #{TRIGGERS}", trigger unless TRIGGERS.include? trigger
|
222
|
+
if trigger.is_a? Hash
|
223
|
+
skip_on_init = trigger.values.first.include? :skip_on_init
|
224
|
+
trigger = trigger.keys.first
|
225
|
+
end
|
226
|
+
block.call if trigger == :each_new_run and !skip_on_init
|
199
227
|
triggers[trigger] << block
|
200
228
|
end
|
201
229
|
|
data/lib/sugar/debug_sugar.rb
CHANGED
@@ -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
|
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
|
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.
|
4
|
+
version: 1.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- garmoshka-mo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|