pry 0.12.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +162 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry.rb +132 -119
- data/lib/pry/basic_object.rb +8 -4
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +43 -51
- data/lib/pry/code.rb +40 -28
- data/lib/pry/code/code_file.rb +28 -24
- data/lib/pry/code/code_range.rb +4 -2
- data/lib/pry/code/loc.rb +15 -8
- data/lib/pry/code_object.rb +40 -38
- data/lib/pry/color_printer.rb +47 -46
- data/lib/pry/command.rb +166 -369
- data/lib/pry/command_set.rb +76 -73
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -81
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat.rb +61 -54
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +71 -60
- data/lib/pry/commands/cat/file_formatter.rb +55 -49
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +44 -39
- data/lib/pry/commands/clear_screen.rb +16 -10
- data/lib/pry/commands/code_collector.rb +148 -133
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +19 -30
- data/lib/pry/commands/edit.rb +184 -161
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/exit.rb +39 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -160
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -150
- data/lib/pry/commands/import_set.rb +20 -16
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls.rb +124 -102
- data/lib/pry/commands/ls/constants.rb +59 -42
- data/lib/pry/commands/ls/formatter.rb +50 -46
- data/lib/pry/commands/ls/globals.rb +38 -34
- data/lib/pry/commands/ls/grep.rb +17 -13
- data/lib/pry/commands/ls/instance_vars.rb +29 -27
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -22
- data/lib/pry/commands/ls/local_vars.rb +38 -28
- data/lib/pry/commands/ls/ls_entity.rb +47 -51
- data/lib/pry/commands/ls/methods.rb +44 -43
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -22
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +27 -22
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +55 -45
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +51 -51
- data/lib/pry/commands/shell_mode.rb +21 -17
- data/lib/pry/commands/show_doc.rb +80 -68
- data/lib/pry/commands/show_info.rb +189 -171
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -45
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression.rb +89 -86
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/whereami.rb +156 -148
- data/lib/pry/commands/wtf.rb +75 -50
- data/lib/pry/config.rb +307 -25
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +9 -7
- data/lib/pry/editor.rb +48 -21
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -16
- data/lib/pry/forwardable.rb +5 -1
- data/lib/pry/helpers.rb +2 -0
- data/lib/pry/helpers/base_helpers.rb +68 -197
- data/lib/pry/helpers/command_helpers.rb +50 -61
- data/lib/pry/helpers/documentation_helpers.rb +20 -13
- data/lib/pry/helpers/options_helpers.rb +14 -7
- data/lib/pry/helpers/platform.rb +7 -5
- data/lib/pry/helpers/table.rb +33 -26
- data/lib/pry/helpers/text.rb +17 -14
- data/lib/pry/history.rb +48 -56
- data/lib/pry/hooks.rb +21 -12
- data/lib/pry/indent.rb +54 -50
- data/lib/pry/input_completer.rb +248 -230
- data/lib/pry/input_lock.rb +8 -9
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method.rb +141 -94
- data/lib/pry/method/disowned.rb +16 -4
- data/lib/pry/method/patcher.rb +12 -3
- data/lib/pry/method/weird_method_locator.rb +68 -44
- data/lib/pry/object_path.rb +33 -25
- data/lib/pry/output.rb +121 -35
- data/lib/pry/pager.rb +186 -180
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -103
- data/lib/pry/pry_instance.rb +217 -215
- data/lib/pry/repl.rb +18 -22
- data/lib/pry/repl_file_loader.rb +27 -21
- data/lib/pry/ring.rb +11 -6
- data/lib/pry/slop.rb +574 -563
- data/lib/pry/slop/commands.rb +164 -169
- data/lib/pry/slop/option.rb +172 -168
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable.rb +59 -61
- data/lib/pry/testable/evalable.rb +21 -12
- data/lib/pry/testable/mockable.rb +18 -10
- data/lib/pry/testable/pry_tester.rb +71 -56
- data/lib/pry/testable/utility.rb +29 -21
- data/lib/pry/testable/variables.rb +49 -43
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +27 -0
- data/lib/pry/wrapped_module.rb +51 -42
- data/lib/pry/wrapped_module/candidate.rb +21 -14
- metadata +35 -35
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gem_readme.rb +0 -25
- data/lib/pry/commands/gem_search.rb +0 -40
- data/lib/pry/commands/gem_stats.rb +0 -83
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -54
- data/lib/pry/config/behavior.rb +0 -255
- data/lib/pry/config/convenience.rb +0 -28
- data/lib/pry/config/default.rb +0 -159
- data/lib/pry/config/memoization.rb +0 -48
- data/lib/pry/platform.rb +0 -91
- data/lib/pry/plugins.rb +0 -122
- data/lib/pry/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
@@ -1,27 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class DisablePry < Pry::ClassCommand
|
6
|
+
match 'disable-pry'
|
7
|
+
group 'Navigating Pry'
|
8
|
+
description 'Stops all future calls to pry and exits the current session.'
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: disable-pry
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
After this command is run any further calls to pry will immediately return `nil`
|
14
|
+
without interrupting the flow of your program. This is particularly useful when
|
15
|
+
you've debugged the problem you were having, and now wish the program to run to
|
16
|
+
the end.
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
As alternatives, consider using `exit!` to force the current Ruby process
|
19
|
+
to quit immediately; or using `edit -p` to remove the `binding.pry`
|
20
|
+
from the code.
|
21
|
+
BANNER
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
def process
|
24
|
+
ENV['DISABLE_PRY'] = 'true'
|
25
|
+
pry_instance.run_command "exit"
|
26
|
+
end
|
23
27
|
end
|
24
|
-
end
|
25
28
|
|
26
|
-
|
29
|
+
Pry::Commands.add_command(Pry::Command::DisablePry)
|
30
|
+
end
|
27
31
|
end
|
@@ -1,26 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
Pry::Commands.instance_eval do
|
3
|
-
command
|
4
|
-
run ".nyancat"
|
5
|
-
end
|
6
|
-
|
7
|
-
command(/!s\/(.*?)\/(.*?)/, "") do |source, dest|
|
5
|
+
command(%r{!s/(.*?)/(.*?)}, "") do |source, dest|
|
8
6
|
eval_string.gsub!(/#{source}/) { dest }
|
9
7
|
run "show-input"
|
10
8
|
end
|
11
9
|
|
12
|
-
command "get-naked", "" do
|
13
|
-
txt = %{
|
14
|
-
--
|
15
|
-
We dont have to take our clothes off to have a good time.
|
16
|
-
We could dance & party all night And drink some cherry wine.
|
17
|
-
-- Jermaine Stewart }
|
18
|
-
output.puts txt
|
19
|
-
txt
|
20
|
-
end
|
21
|
-
|
22
10
|
command "east-coker", "" do
|
23
|
-
txt = %
|
11
|
+
txt = %(
|
24
12
|
--
|
25
13
|
Now the light falls
|
26
14
|
Across the open field, leaving the deep lane
|
@@ -33,13 +21,13 @@ class Pry
|
|
33
21
|
The dahlias sleep in the empty silence.
|
34
22
|
Wait for the early owl.
|
35
23
|
-- T.S Eliot
|
36
|
-
|
24
|
+
)
|
37
25
|
output.puts txt
|
38
26
|
txt
|
39
27
|
end
|
40
28
|
|
41
29
|
command "cohen-poem", "" do
|
42
|
-
txt = %
|
30
|
+
txt = %(
|
43
31
|
--
|
44
32
|
When this American woman,
|
45
33
|
whose thighs are bound in casual red cloth,
|
@@ -56,7 +44,7 @@ class Pry
|
|
56
44
|
that if you turn your head
|
57
45
|
they are lost for hours.
|
58
46
|
-- Leonard Cohen
|
59
|
-
|
47
|
+
)
|
60
48
|
output.puts txt
|
61
49
|
txt
|
62
50
|
end
|
@@ -79,34 +67,35 @@ class Pry
|
|
79
67
|
O abstract hunger for things, impotent libido for moments,
|
80
68
|
Intellectual orgy of feeling life!
|
81
69
|
-- Fernando Pessoa
|
82
|
-
TEXT
|
70
|
+
TEXT
|
83
71
|
end
|
84
72
|
|
85
73
|
command "test-ansi", "" do
|
86
|
-
prev_color =
|
87
|
-
|
74
|
+
prev_color = pry_instance.config.color
|
75
|
+
pry_instance.config.color = true
|
88
76
|
|
89
|
-
picture = unindent <<-'
|
77
|
+
picture = unindent <<-'OUTPUT'.gsub(/[[:alpha:]!]/) { |s| red(s) }
|
90
78
|
____ _______________________
|
91
79
|
/ \ | A W G |
|
92
80
|
/ O O \ | N I O N ! |
|
93
81
|
| | | S S R I ! |
|
94
82
|
\ \__/ / __| I K ! |
|
95
83
|
\____/ \________________________|
|
96
|
-
|
84
|
+
OUTPUT
|
97
85
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
86
|
+
move_up =
|
87
|
+
if Helpers::Platform.windows_ansi?
|
88
|
+
proc { |n| "\e[#{n}F" }
|
89
|
+
else
|
90
|
+
proc { |n| "\e[#{n}A\e[0G" }
|
91
|
+
end
|
103
92
|
|
104
93
|
output.puts "\n" * 6
|
105
94
|
output.puts picture.lines.map(&:chomp).reverse.join(move_up[1])
|
106
95
|
output.puts "\n" * 6
|
107
96
|
output.puts "** ENV['TERM'] is #{ENV['TERM']} **\n\n"
|
108
97
|
|
109
|
-
|
98
|
+
pry_instance.config.color = prev_color
|
110
99
|
end
|
111
100
|
end
|
112
101
|
end
|
data/lib/pry/commands/edit.rb
CHANGED
@@ -1,200 +1,223 @@
|
|
1
|
-
|
2
|
-
class Command::Edit < Pry::ClassCommand
|
3
|
-
require 'pry/commands/edit/exception_patcher'
|
4
|
-
require 'pry/commands/edit/file_and_line_locator'
|
5
|
-
|
6
|
-
match 'edit'
|
7
|
-
group 'Editing'
|
8
|
-
description 'Invoke the default editor on a file.'
|
9
|
-
|
10
|
-
banner <<-'BANNER'
|
11
|
-
Usage: edit [--no-reload|--reload|--patch] [--line LINE] [--temp|--ex|FILE[:LINE]|OBJECT|--in N]
|
12
|
-
|
13
|
-
Open a text editor. When no FILE is given, edits the pry input buffer.
|
14
|
-
When a method/module/command is given, the code is opened in an editor.
|
15
|
-
Ensure `Pry.config.editor` or `_pry_.config.editor` is set to your editor of choice.
|
16
|
-
|
17
|
-
edit sample.rb edit -p MyClass#my_method
|
18
|
-
edit sample.rb --line 105 edit MyClass
|
19
|
-
edit MyClass#my_method edit --ex
|
20
|
-
edit --method edit --ex -p
|
21
|
-
|
22
|
-
https://github.com/pry/pry/wiki/Editor-integration#wiki-Edit_command
|
23
|
-
BANNER
|
24
|
-
|
25
|
-
def options(opt)
|
26
|
-
opt.on :e, :ex, "Open the file that raised the most recent exception (_ex_.file)",
|
27
|
-
optional_argument: true, as: Integer
|
28
|
-
opt.on :i, :in, "Open a temporary file containing the Nth input expression. N may be a range",
|
29
|
-
optional_argument: true, as: Range, default: -1..-1
|
30
|
-
opt.on :t, :temp, "Open an empty temporary file"
|
31
|
-
opt.on :l, :line, "Jump to this line in the opened file",
|
32
|
-
argument: true, as: Integer
|
33
|
-
opt.on :n, :"no-reload", "Don't automatically reload the edited file"
|
34
|
-
opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as returned by `whereami`)"
|
35
|
-
opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)"
|
36
|
-
opt.on :p, :patch, "Instead of editing the object's file, try to edit in a tempfile and apply as a monkey patch"
|
37
|
-
opt.on :m, :method, "Explicitly edit the _current_ method (when inside a method context)."
|
38
|
-
end
|
1
|
+
# frozen_string_literal: true
|
39
2
|
|
40
|
-
|
41
|
-
|
42
|
-
|
3
|
+
class Pry
|
4
|
+
class Command
|
5
|
+
class Edit < Pry::ClassCommand
|
6
|
+
match 'edit'
|
7
|
+
group 'Editing'
|
8
|
+
description 'Invoke the default editor on a file.'
|
9
|
+
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: edit [--no-reload|--reload|--patch] [--line LINE] [--temp|--ex|FILE[:LINE]|OBJECT|--in N]
|
12
|
+
|
13
|
+
Open a text editor. When no FILE is given, edits the pry input buffer.
|
14
|
+
When a method/module/command is given, the code is opened in an editor.
|
15
|
+
Ensure `Pry.config.editor` or `pry_instance.config.editor` is set to your editor of choice.
|
16
|
+
|
17
|
+
edit sample.rb edit -p MyClass#my_method
|
18
|
+
edit sample.rb --line 105 edit MyClass
|
19
|
+
edit MyClass#my_method edit --ex
|
20
|
+
edit --method edit --ex -p
|
21
|
+
|
22
|
+
https://github.com/pry/pry/wiki/Editor-integration#wiki-Edit_command
|
23
|
+
BANNER
|
24
|
+
|
25
|
+
def options(opt)
|
26
|
+
opt.on :e, :ex, "Open the file that raised the most recent exception " \
|
27
|
+
"(_ex_.file)",
|
28
|
+
optional_argument: true, as: Integer
|
29
|
+
opt.on :i, :in, "Open a temporary file containing the Nth input " \
|
30
|
+
"expression. N may be a range",
|
31
|
+
optional_argument: true, as: Range, default: -1..-1
|
32
|
+
opt.on :t, :temp, "Open an empty temporary file"
|
33
|
+
opt.on :l, :line, "Jump to this line in the opened file",
|
34
|
+
argument: true, as: Integer
|
35
|
+
opt.on :n, :"no-reload", "Don't automatically reload the edited file"
|
36
|
+
opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as " \
|
37
|
+
"returned by `whereami`)"
|
38
|
+
opt.on :r, :reload, "Reload the edited code immediately (default for " \
|
39
|
+
"ruby files)"
|
40
|
+
opt.on :p, :patch, "Instead of editing the object's file, try to edit " \
|
41
|
+
"in a tempfile and apply as a monkey patch"
|
42
|
+
opt.on :m, :method, "Explicitly edit the _current_ method (when " \
|
43
|
+
"inside a method context)."
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
def process
|
47
|
+
if bad_option_combination?
|
48
|
+
raise CommandError, "Only one of --ex, --temp, --in, --method and " \
|
49
|
+
"FILE may be specified."
|
50
|
+
end
|
51
|
+
|
52
|
+
if repl_edit?
|
53
|
+
# code defined in pry, eval'd within pry.
|
54
|
+
repl_edit
|
55
|
+
elsif runtime_patch?
|
56
|
+
# patch code without persisting changes, implies future changes are patches
|
57
|
+
apply_runtime_patch
|
58
|
+
else
|
59
|
+
# code stored in actual files, eval'd at top-level
|
60
|
+
file_edit
|
61
|
+
end
|
54
62
|
end
|
55
|
-
end
|
56
63
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
64
|
+
def repl_edit?
|
65
|
+
!opts.present?(:ex) && !opts.present?(:current) && !opts.present?(:method) &&
|
66
|
+
filename_argument.empty?
|
67
|
+
end
|
61
68
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
69
|
+
def repl_edit
|
70
|
+
content = Pry::Editor.new(pry_instance).edit_tempfile_with_content(
|
71
|
+
initial_temp_file_content,
|
72
|
+
initial_temp_file_content.lines.count
|
73
|
+
)
|
74
|
+
pry_instance.eval_string = content
|
75
|
+
Pry.history.push(content)
|
67
76
|
end
|
68
|
-
Pry.history.push(content)
|
69
|
-
end
|
70
77
|
|
71
|
-
|
72
|
-
|
73
|
-
|
78
|
+
def file_based_exception?
|
79
|
+
opts.present?(:ex) && !opts.present?(:patch)
|
80
|
+
end
|
74
81
|
|
75
|
-
|
76
|
-
|
77
|
-
|
82
|
+
def runtime_patch?
|
83
|
+
!file_based_exception? &&
|
84
|
+
(opts.present?(:patch) ||
|
85
|
+
previously_patched?(code_object) ||
|
86
|
+
pry_method?(code_object))
|
87
|
+
end
|
78
88
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
89
|
+
def apply_runtime_patch
|
90
|
+
if patch_exception?
|
91
|
+
ExceptionPatcher.new(
|
92
|
+
pry_instance, state, file_and_line_for_current_exception
|
93
|
+
).perform_patch
|
94
|
+
elsif code_object.is_a?(Pry::Method)
|
95
|
+
code_object.redefine(
|
96
|
+
Pry::Editor.new(pry_instance).edit_tempfile_with_content(
|
97
|
+
code_object.source
|
98
|
+
)
|
99
|
+
)
|
85
100
|
else
|
86
101
|
raise NotImplementedError, "Cannot yet patch #{code_object} objects!"
|
87
102
|
end
|
88
103
|
end
|
89
|
-
end
|
90
104
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
105
|
+
def ensure_file_name_is_valid(file_name)
|
106
|
+
unless file_name
|
107
|
+
raise CommandError, "Cannot find a valid file for #{filename_argument}"
|
108
|
+
end
|
95
109
|
|
96
|
-
|
97
|
-
FileAndLineLocator.from_exception(_pry_.last_exception, opts[:ex].to_i)
|
98
|
-
end
|
110
|
+
return unless not_a_real_file?(file_name)
|
99
111
|
|
100
|
-
|
101
|
-
|
102
|
-
FileAndLineLocator.from_binding(target)
|
103
|
-
elsif opts.present?(:ex)
|
104
|
-
file_and_line_for_current_exception
|
105
|
-
elsif code_object
|
106
|
-
FileAndLineLocator.from_code_object(code_object, filename_argument)
|
107
|
-
else
|
108
|
-
# when file and line are passed as a single arg, e.g my_file.rb:30
|
109
|
-
FileAndLineLocator.from_filename_argument(filename_argument)
|
110
|
-
end
|
111
|
-
|
112
|
-
[file_name, opts.present?(:line) ? opts[:l].to_i : line]
|
113
|
-
end
|
112
|
+
raise CommandError, "#{file_name} is not a valid file name, cannot edit!"
|
113
|
+
end
|
114
114
|
|
115
|
-
|
116
|
-
|
115
|
+
def file_and_line_for_current_exception
|
116
|
+
FileAndLineLocator.from_exception(pry_instance.last_exception, opts[:ex].to_i)
|
117
|
+
end
|
118
|
+
|
119
|
+
def file_and_line
|
120
|
+
file_name, line =
|
121
|
+
if opts.present?(:current)
|
122
|
+
FileAndLineLocator.from_binding(target)
|
123
|
+
elsif opts.present?(:ex)
|
124
|
+
file_and_line_for_current_exception
|
125
|
+
elsif code_object
|
126
|
+
FileAndLineLocator.from_code_object(code_object, filename_argument)
|
127
|
+
else
|
128
|
+
# when file and line are passed as a single arg, e.g my_file.rb:30
|
129
|
+
FileAndLineLocator.from_filename_argument(filename_argument)
|
130
|
+
end
|
131
|
+
|
132
|
+
[file_name, opts.present?(:line) ? opts[:l].to_i : line]
|
133
|
+
end
|
117
134
|
|
118
|
-
|
135
|
+
def file_edit
|
136
|
+
file_name, line = file_and_line
|
119
137
|
|
120
|
-
|
121
|
-
set_file_and_dir_locals(file_name)
|
138
|
+
ensure_file_name_is_valid(file_name)
|
122
139
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
140
|
+
Pry::Editor.new(pry_instance).invoke_editor(file_name, line, reload?(file_name))
|
141
|
+
set_file_and_dir_locals(file_name)
|
142
|
+
|
143
|
+
return unless reload?(file_name)
|
144
|
+
|
145
|
+
silence_warnings { load(file_name) }
|
127
146
|
end
|
128
|
-
end
|
129
147
|
|
130
|
-
|
131
|
-
|
132
|
-
|
148
|
+
def filename_argument
|
149
|
+
args.join(' ')
|
150
|
+
end
|
133
151
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
152
|
+
def code_object
|
153
|
+
@code_object ||=
|
154
|
+
!probably_a_file?(filename_argument) &&
|
155
|
+
Pry::CodeObject.lookup(filename_argument, pry_instance)
|
156
|
+
end
|
138
157
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
158
|
+
def pry_method?(code_object)
|
159
|
+
code_object.is_a?(Pry::Method) &&
|
160
|
+
code_object.pry_method?
|
161
|
+
end
|
143
162
|
|
144
|
-
|
145
|
-
|
146
|
-
|
163
|
+
def previously_patched?(code_object)
|
164
|
+
code_object.is_a?(Pry::Method) &&
|
165
|
+
Pry::Method::Patcher.code_for(code_object.source_location.first)
|
166
|
+
end
|
147
167
|
|
148
|
-
|
149
|
-
|
150
|
-
|
168
|
+
def patch_exception?
|
169
|
+
opts.present?(:ex) && opts.present?(:patch)
|
170
|
+
end
|
151
171
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
172
|
+
def bad_option_combination?
|
173
|
+
[
|
174
|
+
opts.present?(:ex), opts.present?(:temp),
|
175
|
+
opts.present?(:in), opts.present?(:method),
|
176
|
+
!filename_argument.empty?
|
177
|
+
].count(true) > 1
|
178
|
+
end
|
156
179
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
180
|
+
def input_expression
|
181
|
+
case opts[:i]
|
182
|
+
when Range
|
183
|
+
(pry_instance.input_ring[opts[:i]] || []).join
|
184
|
+
when Integer
|
185
|
+
pry_instance.input_ring[opts[:i]] || ""
|
186
|
+
else
|
187
|
+
raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
|
188
|
+
end
|
165
189
|
end
|
166
|
-
end
|
167
190
|
|
168
|
-
|
169
|
-
|
170
|
-
|
191
|
+
def reloadable?
|
192
|
+
opts.present?(:reload) || opts.present?(:ex)
|
193
|
+
end
|
171
194
|
|
172
|
-
|
173
|
-
|
174
|
-
|
195
|
+
def never_reload?
|
196
|
+
opts.present?(:'no-reload') || pry_instance.config.disable_auto_reload
|
197
|
+
end
|
175
198
|
|
176
|
-
|
177
|
-
|
178
|
-
|
199
|
+
def reload?(file_name = "")
|
200
|
+
(reloadable? || file_name.end_with?(".rb")) && !never_reload?
|
201
|
+
end
|
179
202
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
203
|
+
def initial_temp_file_content
|
204
|
+
if opts.present?(:temp)
|
205
|
+
""
|
206
|
+
elsif opts.present?(:in)
|
207
|
+
input_expression
|
208
|
+
elsif eval_string.strip != ""
|
209
|
+
eval_string
|
210
|
+
else
|
211
|
+
pry_instance.input_ring.to_a.reverse_each.find { |x| x && x.strip != "" } || ""
|
212
|
+
end
|
190
213
|
end
|
191
|
-
end
|
192
214
|
|
193
|
-
|
194
|
-
|
195
|
-
|
215
|
+
def probably_a_file?(str)
|
216
|
+
[".rb", ".c", ".py", ".yml", ".gemspec"].include?(File.extname(str)) ||
|
217
|
+
str =~ %r{/|\\}
|
218
|
+
end
|
196
219
|
end
|
197
|
-
end
|
198
220
|
|
199
|
-
|
221
|
+
Pry::Commands.add_command(Pry::Command::Edit)
|
222
|
+
end
|
200
223
|
end
|