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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1b513a3d36e4051c2db1e270a86b70baaaa150e9f1c76046e0cc3af8d213704
4
- data.tar.gz: 10e687ef4ce616be58d8fda903573118078c54a0425c7146b3cc64ff24b356c5
3
+ metadata.gz: 82685576fb9e632b60556d82f67459719b6e202008915e8220c84cbbacd4f65d
4
+ data.tar.gz: 5d0025eb1080c6c4e22510b4996116318eafca80720991274980f32c15bfe9f5
5
5
  SHA512:
6
- metadata.gz: 0e4e758371c47cc09470c8460e191e728040b81fd4496c055cc83f2cee7a4a9d196ddf2e5bb384e9a3ce71b4cf46088651a2c338907c98115a0bb461a8ec4390
7
- data.tar.gz: 2c2cc9896cd78dd420ff0dec84339f084c51e60eb95023d7a5be58cd362a84796d0c7d929862932c8d200cee3179cffae5c836b4c78fe5b6d1e657e56be47409
6
+ metadata.gz: 79b6cbe65d7eec6a06211941082925439555d84538979ee838457ac67f0e057227e88919c9f99ddb6570a5c8e07083b4e39a47055786804d198b5316b1436fd5
7
+ data.tar.gz: ad42f69cde5275f2f533900ec878765f03fe3c57019e5fafd391088324802fd66ba2b61364d0990b8ae5bfbc6b7aaa7c9bec79600577f8a86ec859ecc6faa361
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-moves (1.0.11)
4
+ pry-moves (1.0.13)
5
5
  awesome_print (>= 1.8.0)
6
6
  binding_of_caller (~> 0.7)
7
7
  colorize (~> 0.8)
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 most time-consuming code
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
 
@@ -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
@@ -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
@@ -84,14 +84,17 @@ Pry::Command::Whereami.class_eval do
84
84
  def build_output
85
85
  lines = ['']
86
86
 
87
- formatter = PryMoves::Formatter.new
88
- prefix = Thread.current[:pry_moves_debug] ? "👾 " : ""
89
- # lines << "🍱 #{PryMoves.test_example}" if PryMoves.test_example
90
- lines << "🦆 step_in_everywhere" if PryMoves.step_in_everywhere
91
- lines << "#{prefix}#{formatter.shorten_path location}:#{@line} #{me}"
92
- lines << " ." + formatter.method_signature(target)
93
- lines << ''
94
- lines << "#{code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted}"
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|
@@ -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.12'
2
+ VERSION = '1.0.14'
3
3
  end
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: nil)
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.is_a?(String) ? message : message.ai)
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
- output = obj.ai rescue "#{obj.class} #{obj}"
131
- output.length > MAX_MESSAGE_CHARS ?
132
- output[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : output
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
- TRIGGERS = [:each_new_run, :restart]
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
 
@@ -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
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.12
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: 2024-04-02 00:00:00.000000000 Z
11
+ date: 2025-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry