pry-moves 1.0.3 → 1.0.4

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: cf124819313d4f06ebe4b9d81d1b392cf06e96028ebef3ef67604642f9529c70
4
- data.tar.gz: d07e5afae2c9bf9ce303a1731706af1921f79892496d188b9c5bf371f0160ed1
3
+ metadata.gz: 311be09c5ffb0f48a6aae45f2cf138b4ac8f1c5b285335dd1b358ac5153ca6ab
4
+ data.tar.gz: 66b1eb2eea22582332db51580159ff3ad470dcdd26c2952b5b8846db4928cfb8
5
5
  SHA512:
6
- metadata.gz: ea4608c426807fbc02121a5bc32dddb36fe35fdf988872d964fe97424f9ce0d14d1b8bf28dd96012610ffcfdbb7d2567ceb97589a37b12e49a835c40eddc8fbc
7
- data.tar.gz: d1fca032e8f5c76bd10012b9a170849238c335238ea1b899577c0d2ccb2109b2578b6f171ebcd2f6465f3fdba247c05feef0c9e0a77f481452dfd4c3c270e591
6
+ metadata.gz: 55f69a03e9109a9f55c277242318475ef22cbf4776f885f4a2a3d8bab2ec66e83f6896ab305443dc7d5a6797db6bf7bc97644185e98ba18185792161d87dda8d
7
+ data.tar.gz: ec9e017b99cd33292fd49c5458a9fbe5abb3391a8966032cc9d7aa40f69051fddd83bffbe12b24e1f2e4724458b01893bf8a193934babb3b02e26c1f816b8e3f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-moves (1.0.3)
4
+ pry-moves (1.0.4)
5
5
  awesome_print (>= 1.8.0)
6
6
  binding_of_caller (~> 0.7)
7
7
  colorize (~> 0.8)
data/README.md CHANGED
@@ -93,6 +93,7 @@ PryMoves::Backtrace::filter =
93
93
 
94
94
  Turn off features with environment variables:
95
95
  ```bash
96
+ PRY_MOVES=off
96
97
  PRY_MOVES_DEBUG_MISSING=off
97
98
  PRY_MOVES_RELOADER=off
98
99
  ```
@@ -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
- @timestamps[path] = File.mtime(path)
14
- load path
15
- # Log.info "⚡️ file reloaded #{path}"
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]
@@ -112,8 +112,14 @@ module PryMoves
112
112
  return
113
113
  end
114
114
 
115
- input = Pry.config.original_user_input || action
115
+ input = Pry.config.original_user_input || action.to_s
116
+ return if input == 'next' # ruby keyword
116
117
  binding_value = target.eval(input) rescue nil
118
+ # begin # for debug
119
+ # binding_value = target.eval(input)
120
+ # rescue => e
121
+ # puts (e.backtrace.reverse + ["var_precedence exception:".red, "#{e}".red]).join "\n"
122
+ # end
117
123
  unless binding_value.nil?
118
124
  puts "ℹ️️ Variable \"#{input}\" found. To execute command type its alias or \\#{input}"
119
125
  puts PryMoves::Painter.colorize binding_value
@@ -40,7 +40,11 @@ class PryMoves::Formatter
40
40
  end
41
41
 
42
42
  def format_arg binding, arg_name
43
- arg = binding.eval(arg_name.to_s)
43
+ arg = begin
44
+ binding.eval(arg_name.to_s)
45
+ rescue Exception
46
+ "?"
47
+ end
44
48
  format_obj arg
45
49
  end
46
50
 
@@ -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
- result = run_origin_for_pry_moves command_string, *args
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
 
@@ -93,7 +93,11 @@ Pry::Command::Whereami.class_eval do
93
93
  lines << "#{code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted}"
94
94
 
95
95
  lines << PryMoves::Watch.instance.output(target) unless PryMoves::Watch.instance.empty?
96
- lines.concat PryMoves.messages
96
+ lines.concat(PryMoves.messages.map do |message|
97
+ message
98
+ # message.length > MAX_MESSAGE_CHARS ?
99
+ # message[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : message
100
+ end)
97
101
  PryMoves.messages.clear
98
102
 
99
103
  lines << ''
@@ -7,13 +7,13 @@ 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
12
  re_execution
12
13
  rescue PryMoves::Restart
13
14
  puts "🔄️ Restarting execution"
14
15
  self.restart_requested = false
15
16
  PryMoves.reset
16
- PryMoves.reloader&.reload
17
17
  trigger :restart, context
18
18
  context[:retry] += 1
19
19
  retry
@@ -1,3 +1,3 @@
1
1
  module PryMoves
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
data/lib/pry-moves.rb CHANGED
@@ -23,7 +23,8 @@ module PryMoves
23
23
 
24
24
  def reset
25
25
  self.launched_specs_examples = 0
26
- self.stop_on_breakpoints = true
26
+ self.stop_on_breakpoints = true unless ENV['PRY_MOVES'] == 'off' ||
27
+ (defined?(Rails) and Rails.env.production?)
27
28
  self.debug_called_times = 0
28
29
  self.step_in_everywhere = false
29
30
  end
@@ -45,24 +46,41 @@ module PryMoves
45
46
 
46
47
  ROOT_DIR = File.expand_path(".")
47
48
 
48
- def runtime_debug(instance)
49
+ def runtime_debug(instance, external: false)
49
50
  do_debug = (
50
51
  stop_on_breakpoints and
51
52
  not open? and
52
- caller[1].start_with?(ROOT_DIR) and
53
+ (external or is_project_file?) and
53
54
  not [RubyVM::InstructionSequence].include?(instance)
54
55
  )
55
56
  if do_debug
56
57
  hide_from_stack = true
57
- err = yield
58
+ err, obj = yield
58
59
  # HINT: when pry failed to start use: caller.reverse
59
- PryMoves.debug_error err
60
+ PryMoves.debug_error err, obj
60
61
  true
61
62
  end
62
63
  end
63
64
 
64
- def debug_error(message)
65
+ def is_project_file?
66
+ files = caller[2..3] # -2 steps upside: runtime_debug, debug sugar function
67
+ files.any? do |file|
68
+ !file.start_with?("/") || file.start_with?(ROOT_DIR)
69
+ end
70
+ end
71
+
72
+ MAX_MESSAGE_CHARS = 520
73
+ def format_debug_object obj
74
+ output = obj.ai rescue "#{obj.class} #{obj}"
75
+ output.length > MAX_MESSAGE_CHARS ?
76
+ output[0 .. MAX_MESSAGE_CHARS] + "... (cut)" : output
77
+ end
78
+
79
+ def debug_error(message, debug_object=nil)
65
80
  pry_moves_stack_end = true
81
+ if debug_object
82
+ message = [format_debug_object(debug_object), message].join "\n"
83
+ end
66
84
  debug message, options: {is_error: true}
67
85
  end
68
86
 
@@ -5,30 +5,22 @@ 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) and
9
- not caller[0].match PryMoves::Backtrace::filter
8
+ not ([:begin, :to_s, :to_str, :to_int, :to_ary, :to_io, :to_hash].include? method)
9
+
10
+ # not ([:begin, :to_s, :to_str, :to_int, :to_ary, :to_io, :to_hash].include? method) and
11
+ # not caller[0].match PryMoves::Backtrace::filter
10
12
  )
11
13
 
12
14
  PryMoves.runtime_debug(self) do
13
15
  message = self.nil? ?
14
16
  "\e[31mCalling \e[1m#{method}\e[0m\e[31m on nil\e[0m" :
15
17
  "\e[31mMethod \e[1m#{method}\e[0m\e[31m missing\e[0m"
16
- subject = self.ai rescue "#{self.class} #{self}"
17
- "#{subject}\n" +
18
- "😱 #{message}"
18
+ [message, self]
19
19
  end if debug_missing_method
20
20
 
21
21
  super
22
22
  end
23
23
 
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
24
  def self.const_missing(name)
33
25
  super
34
26
  rescue => e
@@ -40,5 +32,5 @@ Object.class_eval do
40
32
  raise
41
33
  end unless defined?(Rails)
42
34
 
43
- end if ENV['PRY_MOVES_DEBUG_MISSING'] != 'off' and
35
+ end if ENV['PRY_MOVES_DEBUG_MISSING'] != 'off' and ENV['PRY_MOVES'] != 'off' and
44
36
  not (defined?(Rails) and Rails.env.production?)
@@ -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
- lines = [err.red]
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.ai if 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
@@ -39,6 +37,14 @@ Object.class_eval do
39
37
  self
40
38
  end
41
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
45
+ self
46
+ end
47
+
42
48
  end
43
49
 
44
50
  RSpec.configure do |config|
@@ -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
 
@@ -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
@@ -1,3 +1,6 @@
1
- bundle exec rspec && \
2
- gem build pry-moves.gemspec && \
1
+ set -e
2
+ set -o pipefail
3
+
4
+ bundle exec rspec
5
+ gem build pry-moves.gemspec
3
6
  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: 1.0.3
4
+ version: 1.0.4
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: 2022-12-21 00:00:00.000000000 Z
11
+ date: 2022-12-29 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: