pry-moves 1.0.3 → 1.0.5
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 +1 -0
- data/lib/commands/next_breakpoint.rb +4 -0
- data/lib/pry-moves/backtrace.rb +1 -0
- data/lib/pry-moves/code_reloader.rb +13 -3
- data/lib/pry-moves/commands.rb +6 -3
- data/lib/pry-moves/formatter.rb +5 -1
- data/lib/pry-moves/painter.rb +10 -0
- data/lib/pry-moves/pry_ext.rb +8 -3
- data/lib/pry-moves/pry_wrapper.rb +1 -0
- data/lib/pry-moves/restartable.rb +6 -4
- data/lib/pry-moves/version.rb +1 -1
- data/lib/pry-moves.rb +39 -9
- data/lib/sugar/debug_of_missing.rb +4 -14
- data/lib/sugar/debug_sugar.rb +15 -9
- data/publish.sh +5 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 301fded3cbdfbcafed7b5387b820b8c1366be09023f0462a8ab1a36a7bbcc563
|
4
|
+
data.tar.gz: bfb140a999ccc293ca3f81ab11b2ea456c48f21c5a62902c6a44e6c6453e2baa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 794091fb89ac6ab0b9b2de60dc960137dd72068368caafb6302e6b5731835c3d0d36db7526524c7d6b47104eaf1293aec779a9bb4bfcb45aa1a22a3dd71484c2
|
7
|
+
data.tar.gz: 816e6e90426305ea3b08ed9bfa1899106a3870b782a25cef59abfc3462d7ffa99fa081cae74acb0acfced7126267176c2b6af32fae6510b0e72a4217bd6bb95c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,10 @@ class PryMoves::NextBreakpoint < PryMoves::TraceCommand
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def trace(event, file, line, method, binding_)
|
7
|
+
# this command will stuck in tracing when no breakpoint met (usually)
|
8
|
+
PryMoves.messages << "⚠️ Command NextBreakpoint is not implemented"
|
9
|
+
return true
|
10
|
+
|
7
11
|
if binding_.local_variable_defined?(:pry_breakpoint) and
|
8
12
|
binding_.local_variable_get(:pry_breakpoint)
|
9
13
|
binding_.local_variable_set :pry_breakpoint, nil # reset breakpoint at visited method instance
|
data/lib/pry-moves/backtrace.rb
CHANGED
@@ -10,15 +10,25 @@ class CodeReloader
|
|
10
10
|
def reload
|
11
11
|
traverse_files do |path|
|
12
12
|
if @timestamps[path] != File.mtime(path)
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
if reload_file path
|
14
|
+
@timestamps[path] = File.mtime(path)
|
15
|
+
# Log.info "⚡️ file reloaded #{path}"
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
22
|
|
23
|
+
def reload_file path
|
24
|
+
hide_from_stack = true
|
25
|
+
load path
|
26
|
+
true
|
27
|
+
rescue SyntaxError => e
|
28
|
+
PryMoves.debug_error ["🛠 Syntax error:".red, e.message].join "\n"
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
22
32
|
def traverse_files
|
23
33
|
paths = PryMoves.reload_ruby_scripts[:monitor]
|
24
34
|
except = PryMoves.reload_ruby_scripts[:except]
|
data/lib/pry-moves/commands.rb
CHANGED
@@ -112,12 +112,15 @@ module PryMoves
|
|
112
112
|
return
|
113
113
|
end
|
114
114
|
|
115
|
-
input = Pry.config.original_user_input || action
|
116
|
-
|
117
|
-
|
115
|
+
input = Pry.config.original_user_input || action.to_s
|
116
|
+
return if %w[next debug].include? input # next - ruby keyword
|
117
|
+
begin
|
118
|
+
binding_value = target.eval(input)
|
118
119
|
puts "ℹ️️ Variable \"#{input}\" found. To execute command type its alias or \\#{input}"
|
119
120
|
puts PryMoves::Painter.colorize binding_value
|
120
121
|
true
|
122
|
+
rescue => e
|
123
|
+
# puts (e.backtrace.reverse + ["var_precedence exception:".red, "#{e}".red]).join "\n"
|
121
124
|
end
|
122
125
|
end
|
123
126
|
|
data/lib/pry-moves/formatter.rb
CHANGED
data/lib/pry-moves/painter.rb
CHANGED
@@ -12,10 +12,20 @@ module PryMoves::Painter
|
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
+
class ShortInspector
|
16
|
+
def initialize obj
|
17
|
+
@obj = obj
|
18
|
+
end
|
19
|
+
def inspect
|
20
|
+
@obj.short_inspect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
def self.colorize(obj)
|
16
25
|
colored_str = Canvas.new
|
17
26
|
i = obj.inspect
|
18
27
|
obj = obj.class if i.is_a?(String) && i.start_with?("#<")
|
28
|
+
obj = ShortInspector.new(obj) if obj.respond_to?(:short_inspect)
|
19
29
|
catch (:cut) do
|
20
30
|
Pry::ColorPrinter.pp obj, colored_str
|
21
31
|
end
|
data/lib/pry-moves/pry_ext.rb
CHANGED
@@ -42,9 +42,9 @@ Pry::Command.class_eval do
|
|
42
42
|
alias run_origin_for_pry_moves run
|
43
43
|
def run(command_string, *args)
|
44
44
|
Pry.config.original_user_input = self.class.original_user_input
|
45
|
-
|
45
|
+
run_origin_for_pry_moves command_string, *args
|
46
|
+
ensure
|
46
47
|
Pry.config.original_user_input = nil
|
47
|
-
result
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -86,6 +86,7 @@ Pry::Command::Whereami.class_eval do
|
|
86
86
|
|
87
87
|
formatter = PryMoves::Formatter.new
|
88
88
|
prefix = Thread.current[:pry_moves_debug] ? "👾 " : ""
|
89
|
+
# lines << "🍱 #{PryMoves.test_example}" if PryMoves.test_example
|
89
90
|
lines << "🦆 step_in_everywhere" if PryMoves.step_in_everywhere
|
90
91
|
lines << "#{prefix}#{formatter.shorten_path location}:#{@line} #{me}"
|
91
92
|
lines << " ." + formatter.method_signature(target)
|
@@ -93,7 +94,11 @@ Pry::Command::Whereami.class_eval do
|
|
93
94
|
lines << "#{code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted}"
|
94
95
|
|
95
96
|
lines << PryMoves::Watch.instance.output(target) unless PryMoves::Watch.instance.empty?
|
96
|
-
lines.concat
|
97
|
+
lines.concat(PryMoves.messages.map do |message|
|
98
|
+
message
|
99
|
+
# message.length > MAX_MESSAGE_CHARS ?
|
100
|
+
# message[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : message
|
101
|
+
end)
|
97
102
|
PryMoves.messages.clear
|
98
103
|
|
99
104
|
lines << ''
|
@@ -7,13 +7,12 @@ module PryMoves::Restartable
|
|
7
7
|
def restartable context
|
8
8
|
trigger :each_new_run, context
|
9
9
|
context[:retry] ||= 0
|
10
|
+
PryMoves.reloader&.reload if context[:retry] > 0
|
10
11
|
yield context
|
11
|
-
re_execution
|
12
|
+
re_execution # todo: maybe mark restart_request for thread? not globally?
|
12
13
|
rescue PryMoves::Restart
|
13
14
|
puts "🔄️ Restarting execution"
|
14
|
-
self.restart_requested = false
|
15
15
|
PryMoves.reset
|
16
|
-
PryMoves.reloader&.reload
|
17
16
|
trigger :restart, context
|
18
17
|
context[:retry] += 1
|
19
18
|
retry
|
@@ -23,7 +22,10 @@ module PryMoves::Restartable
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def re_execution
|
26
|
-
|
25
|
+
if restart_requested
|
26
|
+
self.restart_requested = false
|
27
|
+
raise PryMoves::Restart
|
28
|
+
end
|
27
29
|
raise PryMoves::Reload if reload_requested
|
28
30
|
end
|
29
31
|
|
data/lib/pry-moves/version.rb
CHANGED
data/lib/pry-moves.rb
CHANGED
@@ -7,14 +7,23 @@ module PryMoves
|
|
7
7
|
extend PryMoves::Restartable
|
8
8
|
|
9
9
|
attr_accessor :is_open, :trace, :stack_tips,
|
10
|
-
:stop_on_breakpoints,
|
10
|
+
:stop_on_breakpoints,
|
11
|
+
:test_example, :launched_specs_examples,
|
11
12
|
:debug_called_times, :step_in_everywhere
|
12
13
|
|
14
|
+
def loop
|
15
|
+
Kernel.loop do
|
16
|
+
result = yield
|
17
|
+
debug "⏸ execution loop complete\n#{result}"
|
18
|
+
PryMoves.reloader&.reload
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
13
22
|
def init
|
14
23
|
reset
|
15
24
|
self.trace = true if ENV['TRACE_MOVES']
|
16
25
|
self.reload_ruby_scripts = {
|
17
|
-
monitor: %w(app spec),
|
26
|
+
monitor: %w(app test spec),
|
18
27
|
except: %w(app/assets app/views)
|
19
28
|
}
|
20
29
|
self.reloader = CodeReloader.new unless ENV['PRY_MOVES_RELOADER'] == 'off'
|
@@ -23,13 +32,17 @@ module PryMoves
|
|
23
32
|
|
24
33
|
def reset
|
25
34
|
self.launched_specs_examples = 0
|
26
|
-
|
35
|
+
unless ENV['PRY_MOVES'] == 'off' ||
|
36
|
+
(defined?(Rails) and Rails.env.production?)
|
37
|
+
self.stop_on_breakpoints = STDIN.tty? && STDOUT.tty?
|
38
|
+
end
|
27
39
|
self.debug_called_times = 0
|
28
40
|
self.step_in_everywhere = false
|
29
41
|
end
|
30
42
|
|
31
|
-
def debug(message = nil, at: nil, from: nil, options: nil)
|
43
|
+
def debug(message = nil, data: nil, at: nil, from: nil, options: nil)
|
32
44
|
pry_moves_stack_end = true
|
45
|
+
message ||= data
|
33
46
|
PryMoves.re_execution
|
34
47
|
if PryMoves.stop_on_breakpoints
|
35
48
|
self.debug_called_times += 1
|
@@ -45,24 +58,41 @@ module PryMoves
|
|
45
58
|
|
46
59
|
ROOT_DIR = File.expand_path(".")
|
47
60
|
|
48
|
-
def runtime_debug(instance)
|
61
|
+
def runtime_debug(instance, external: false)
|
49
62
|
do_debug = (
|
50
63
|
stop_on_breakpoints and
|
51
64
|
not open? and
|
52
|
-
|
65
|
+
(external or is_project_file?) and
|
53
66
|
not [RubyVM::InstructionSequence].include?(instance)
|
54
67
|
)
|
55
68
|
if do_debug
|
56
69
|
hide_from_stack = true
|
57
|
-
err = yield
|
70
|
+
err, obj = yield
|
58
71
|
# HINT: when pry failed to start use: caller.reverse
|
59
|
-
PryMoves.debug_error err
|
72
|
+
PryMoves.debug_error err, obj
|
60
73
|
true
|
61
74
|
end
|
62
75
|
end
|
63
76
|
|
64
|
-
def
|
77
|
+
def is_project_file?
|
78
|
+
files = caller[2..4] # -2 steps upside: runtime_debug, debug sugar function
|
79
|
+
files.any? do |file|
|
80
|
+
!file.start_with?("/") || file.start_with?(ROOT_DIR)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
MAX_MESSAGE_CHARS = 520
|
85
|
+
def format_debug_object obj
|
86
|
+
output = obj.ai rescue "#{obj.class} #{obj}"
|
87
|
+
output.length > MAX_MESSAGE_CHARS ?
|
88
|
+
output[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : output
|
89
|
+
end
|
90
|
+
|
91
|
+
def debug_error(message, debug_object=nil)
|
65
92
|
pry_moves_stack_end = true
|
93
|
+
if debug_object
|
94
|
+
message = [format_debug_object(debug_object), message].join "\n"
|
95
|
+
end
|
66
96
|
debug message, options: {is_error: true}
|
67
97
|
end
|
68
98
|
|
@@ -5,30 +5,20 @@ Object.class_eval do
|
|
5
5
|
pry_cancel_debug = true
|
6
6
|
|
7
7
|
debug_missing_method = (
|
8
|
-
not ([:begin, :to_s, :to_str, :to_int, :to_ary, :to_io, :to_hash].include? method)
|
9
|
-
|
8
|
+
not ([:begin, :to_s, :to_str, :to_int, :to_r, :to_ary, :to_io, :to_hash].include? method)
|
9
|
+
# not caller[0].match PryMoves::Backtrace::filter
|
10
10
|
)
|
11
11
|
|
12
12
|
PryMoves.runtime_debug(self) do
|
13
13
|
message = self.nil? ?
|
14
14
|
"\e[31mCalling \e[1m#{method}\e[0m\e[31m on nil\e[0m" :
|
15
15
|
"\e[31mMethod \e[1m#{method}\e[0m\e[31m missing\e[0m"
|
16
|
-
|
17
|
-
"#{subject}\n" +
|
18
|
-
"😱 #{message}"
|
16
|
+
[message, self]
|
19
17
|
end if debug_missing_method
|
20
18
|
|
21
19
|
super
|
22
20
|
end
|
23
21
|
|
24
|
-
def should_be *classes
|
25
|
-
hide_from_stack = true
|
26
|
-
if self && !classes.some?{self.is_a?(_1)}
|
27
|
-
error("Expected class #{classes.join ", "}, got #{self.class.ai}", self)
|
28
|
-
end
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
22
|
def self.const_missing(name)
|
33
23
|
super
|
34
24
|
rescue => e
|
@@ -40,5 +30,5 @@ Object.class_eval do
|
|
40
30
|
raise
|
41
31
|
end unless defined?(Rails)
|
42
32
|
|
43
|
-
end if ENV['PRY_MOVES_DEBUG_MISSING'] != 'off' and
|
33
|
+
end if ENV['PRY_MOVES_DEBUG_MISSING'] != 'off' and ENV['PRY_MOVES'] != 'off' and
|
44
34
|
not (defined?(Rails) and Rails.env.production?)
|
data/lib/sugar/debug_sugar.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
def debug *args
|
2
|
-
return binding.pry_forced if args.first
|
2
|
+
return binding.pry_forced if [:force, :forced].include? args.first
|
3
3
|
pry_moves_stack_end = true
|
4
4
|
PryMoves.debug *args
|
5
5
|
end
|
@@ -9,11 +9,9 @@ def error(msg = "Error", debug_object = nil)
|
|
9
9
|
err = "😱 #{msg}"
|
10
10
|
unless PryMoves.open?
|
11
11
|
if PryMoves.stop_on_breakpoints
|
12
|
-
|
13
|
-
lines.prepend debug_object.ai if debug_object
|
14
|
-
PryMoves.debug_error lines.join("\n")
|
12
|
+
PryMoves.debug_error err.red, debug_object
|
15
13
|
else
|
16
|
-
STDERR.puts debug_object
|
14
|
+
STDERR.puts PryMoves.format_debug_object(debug_object) if debug_object
|
17
15
|
STDERR.puts err.ljust(80, ' ').red
|
18
16
|
end
|
19
17
|
end
|
@@ -35,7 +33,15 @@ Object.class_eval do
|
|
35
33
|
|
36
34
|
def required!
|
37
35
|
pry_moves_stack_end = true
|
38
|
-
error("required parameter is missing") if self.nil?
|
36
|
+
error("required parameter is missing", self) if self.nil?
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def should_be *classes
|
41
|
+
hide_from_stack = true
|
42
|
+
if self && !classes.some?{self.is_a?(_1)}
|
43
|
+
error("Expected class #{classes.join ", "}, got #{self.class.ai}", self)
|
44
|
+
end
|
39
45
|
self
|
40
46
|
end
|
41
47
|
|
@@ -55,7 +61,7 @@ RSpec.configure do |config|
|
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
58
|
-
end if defined? RSpec
|
64
|
+
end if ENV['PRY_MOVES'] != 'off' and defined? RSpec
|
59
65
|
|
60
66
|
Rake::Task.class_eval do
|
61
67
|
|
@@ -63,7 +69,7 @@ Rake::Task.class_eval do
|
|
63
69
|
|
64
70
|
def execute(args=nil)
|
65
71
|
args ||= EMPTY_TASK_ARGS
|
66
|
-
PryMoves.restartable(rake_args: args) do |context|
|
72
|
+
PryMoves.restartable(rake_args: args, name: self.name) do |context|
|
67
73
|
reload_actions if PryMoves.reload_rake_tasks and context[:retry] > 0
|
68
74
|
execute_origin_for_pry_moves args
|
69
75
|
end
|
@@ -75,7 +81,7 @@ Rake::Task.class_eval do
|
|
75
81
|
load rake_task_path
|
76
82
|
end
|
77
83
|
|
78
|
-
end if defined? Rake and defined? Rake::Task
|
84
|
+
end if ENV['PRY_MOVES'] != 'off' and defined? Rake and defined? Rake::Task
|
79
85
|
|
80
86
|
Diffy.module_eval do
|
81
87
|
|
data/publish.sh
CHANGED
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- garmoshka-mo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -179,7 +179,7 @@ homepage: https://github.com/garmoshka-mo/pry-moves
|
|
179
179
|
licenses:
|
180
180
|
- MIT
|
181
181
|
metadata: {}
|
182
|
-
post_install_message:
|
182
|
+
post_install_message:
|
183
183
|
rdoc_options: []
|
184
184
|
require_paths:
|
185
185
|
- lib
|
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
198
|
version: '0'
|
199
199
|
requirements: []
|
200
200
|
rubygems_version: 3.1.6
|
201
|
-
signing_key:
|
201
|
+
signing_key:
|
202
202
|
specification_version: 4
|
203
203
|
summary: Debugger for ruby
|
204
204
|
test_files:
|