super-smart-mod 0.0.1
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 +7 -0
- data/pry-0.16.0/CHANGELOG.md +1211 -0
- data/pry-0.16.0/LICENSE +25 -0
- data/pry-0.16.0/README.md +469 -0
- data/pry-0.16.0/bin/pry +13 -0
- data/pry-0.16.0/lib/pry/basic_object.rb +10 -0
- data/pry-0.16.0/lib/pry/block_command.rb +22 -0
- data/pry-0.16.0/lib/pry/class_command.rb +194 -0
- data/pry-0.16.0/lib/pry/cli.rb +211 -0
- data/pry-0.16.0/lib/pry/code/code_file.rb +114 -0
- data/pry-0.16.0/lib/pry/code/code_range.rb +73 -0
- data/pry-0.16.0/lib/pry/code/loc.rb +105 -0
- data/pry-0.16.0/lib/pry/code.rb +357 -0
- data/pry-0.16.0/lib/pry/code_object.rb +197 -0
- data/pry-0.16.0/lib/pry/color_printer.rb +66 -0
- data/pry-0.16.0/lib/pry/command.rb +520 -0
- data/pry-0.16.0/lib/pry/command_set.rb +418 -0
- data/pry-0.16.0/lib/pry/command_state.rb +36 -0
- data/pry-0.16.0/lib/pry/commands/amend_line.rb +103 -0
- data/pry-0.16.0/lib/pry/commands/bang.rb +24 -0
- data/pry-0.16.0/lib/pry/commands/bang_pry.rb +21 -0
- data/pry-0.16.0/lib/pry/commands/cat/abstract_formatter.rb +32 -0
- data/pry-0.16.0/lib/pry/commands/cat/exception_formatter.rb +90 -0
- data/pry-0.16.0/lib/pry/commands/cat/file_formatter.rb +77 -0
- data/pry-0.16.0/lib/pry/commands/cat/input_expression_formatter.rb +48 -0
- data/pry-0.16.0/lib/pry/commands/cat.rb +70 -0
- data/pry-0.16.0/lib/pry/commands/cd.rb +48 -0
- data/pry-0.16.0/lib/pry/commands/change_inspector.rb +34 -0
- data/pry-0.16.0/lib/pry/commands/change_prompt.rb +51 -0
- data/pry-0.16.0/lib/pry/commands/clear_screen.rb +20 -0
- data/pry-0.16.0/lib/pry/commands/code_collector.rb +182 -0
- data/pry-0.16.0/lib/pry/commands/disable_pry.rb +31 -0
- data/pry-0.16.0/lib/pry/commands/easter_eggs.rb +101 -0
- data/pry-0.16.0/lib/pry/commands/edit/exception_patcher.rb +29 -0
- data/pry-0.16.0/lib/pry/commands/edit/file_and_line_locator.rb +47 -0
- data/pry-0.16.0/lib/pry/commands/edit.rb +225 -0
- data/pry-0.16.0/lib/pry/commands/exit.rb +47 -0
- data/pry-0.16.0/lib/pry/commands/exit_all.rb +33 -0
- data/pry-0.16.0/lib/pry/commands/exit_program.rb +27 -0
- data/pry-0.16.0/lib/pry/commands/find_method.rb +199 -0
- data/pry-0.16.0/lib/pry/commands/fix_indent.rb +23 -0
- data/pry-0.16.0/lib/pry/commands/help.rb +171 -0
- data/pry-0.16.0/lib/pry/commands/hist.rb +182 -0
- data/pry-0.16.0/lib/pry/commands/import_set.rb +27 -0
- data/pry-0.16.0/lib/pry/commands/jump_to.rb +33 -0
- data/pry-0.16.0/lib/pry/commands/list_inspectors.rb +42 -0
- data/pry-0.16.0/lib/pry/commands/ls/config.rb +54 -0
- data/pry-0.16.0/lib/pry/commands/ls/constants.rb +75 -0
- data/pry-0.16.0/lib/pry/commands/ls/formatter.rb +55 -0
- data/pry-0.16.0/lib/pry/commands/ls/globals.rb +50 -0
- data/pry-0.16.0/lib/pry/commands/ls/grep.rb +23 -0
- data/pry-0.16.0/lib/pry/commands/ls/instance_vars.rb +40 -0
- data/pry-0.16.0/lib/pry/commands/ls/interrogatable.rb +24 -0
- data/pry-0.16.0/lib/pry/commands/ls/jruby_hacks.rb +55 -0
- data/pry-0.16.0/lib/pry/commands/ls/local_names.rb +37 -0
- data/pry-0.16.0/lib/pry/commands/ls/local_vars.rb +47 -0
- data/pry-0.16.0/lib/pry/commands/ls/ls_entity.rb +65 -0
- data/pry-0.16.0/lib/pry/commands/ls/methods.rb +55 -0
- data/pry-0.16.0/lib/pry/commands/ls/methods_helper.rb +50 -0
- data/pry-0.16.0/lib/pry/commands/ls/self_methods.rb +34 -0
- data/pry-0.16.0/lib/pry/commands/ls.rb +114 -0
- data/pry-0.16.0/lib/pry/commands/nesting.rb +29 -0
- data/pry-0.16.0/lib/pry/commands/play.rb +113 -0
- data/pry-0.16.0/lib/pry/commands/pry_backtrace.rb +30 -0
- data/pry-0.16.0/lib/pry/commands/pry_version.rb +21 -0
- data/pry-0.16.0/lib/pry/commands/raise_up.rb +38 -0
- data/pry-0.16.0/lib/pry/commands/reload_code.rb +74 -0
- data/pry-0.16.0/lib/pry/commands/reset.rb +22 -0
- data/pry-0.16.0/lib/pry/commands/ri.rb +75 -0
- data/pry-0.16.0/lib/pry/commands/save_file.rb +63 -0
- data/pry-0.16.0/lib/pry/commands/shell_command.rb +75 -0
- data/pry-0.16.0/lib/pry/commands/shell_mode.rb +30 -0
- data/pry-0.16.0/lib/pry/commands/show_doc.rb +84 -0
- data/pry-0.16.0/lib/pry/commands/show_info.rb +234 -0
- data/pry-0.16.0/lib/pry/commands/show_input.rb +22 -0
- data/pry-0.16.0/lib/pry/commands/show_source.rb +57 -0
- data/pry-0.16.0/lib/pry/commands/stat.rb +44 -0
- data/pry-0.16.0/lib/pry/commands/switch_to.rb +29 -0
- data/pry-0.16.0/lib/pry/commands/toggle_color.rb +28 -0
- data/pry-0.16.0/lib/pry/commands/watch_expression/expression.rb +43 -0
- data/pry-0.16.0/lib/pry/commands/watch_expression.rb +108 -0
- data/pry-0.16.0/lib/pry/commands/whereami.rb +205 -0
- data/pry-0.16.0/lib/pry/commands/wtf.rb +95 -0
- data/pry-0.16.0/lib/pry/config/attributable.rb +22 -0
- data/pry-0.16.0/lib/pry/config/lazy_value.rb +29 -0
- data/pry-0.16.0/lib/pry/config/memoized_value.rb +34 -0
- data/pry-0.16.0/lib/pry/config/value.rb +24 -0
- data/pry-0.16.0/lib/pry/config.rb +321 -0
- data/pry-0.16.0/lib/pry/control_d_handler.rb +28 -0
- data/pry-0.16.0/lib/pry/core_extensions.rb +144 -0
- data/pry-0.16.0/lib/pry/editor.rb +157 -0
- data/pry-0.16.0/lib/pry/env.rb +18 -0
- data/pry-0.16.0/lib/pry/exception_handler.rb +48 -0
- data/pry-0.16.0/lib/pry/exceptions.rb +73 -0
- data/pry-0.16.0/lib/pry/forwardable.rb +27 -0
- data/pry-0.16.0/lib/pry/helpers/base_helpers.rb +71 -0
- data/pry-0.16.0/lib/pry/helpers/command_helpers.rb +146 -0
- data/pry-0.16.0/lib/pry/helpers/documentation_helpers.rb +84 -0
- data/pry-0.16.0/lib/pry/helpers/options_helpers.rb +34 -0
- data/pry-0.16.0/lib/pry/helpers/platform.rb +55 -0
- data/pry-0.16.0/lib/pry/helpers/table.rb +121 -0
- data/pry-0.16.0/lib/pry/helpers/text.rb +118 -0
- data/pry-0.16.0/lib/pry/helpers.rb +8 -0
- data/pry-0.16.0/lib/pry/history.rb +153 -0
- data/pry-0.16.0/lib/pry/hooks.rb +180 -0
- data/pry-0.16.0/lib/pry/indent.rb +414 -0
- data/pry-0.16.0/lib/pry/input/simple_stdio.rb +13 -0
- data/pry-0.16.0/lib/pry/input_completer.rb +283 -0
- data/pry-0.16.0/lib/pry/input_lock.rb +129 -0
- data/pry-0.16.0/lib/pry/inspector.rb +39 -0
- data/pry-0.16.0/lib/pry/last_exception.rb +61 -0
- data/pry-0.16.0/lib/pry/method/disowned.rb +67 -0
- data/pry-0.16.0/lib/pry/method/patcher.rb +131 -0
- data/pry-0.16.0/lib/pry/method/weird_method_locator.rb +222 -0
- data/pry-0.16.0/lib/pry/method.rb +599 -0
- data/pry-0.16.0/lib/pry/object_path.rb +91 -0
- data/pry-0.16.0/lib/pry/output.rb +136 -0
- data/pry-0.16.0/lib/pry/pager.rb +249 -0
- data/pry-0.16.0/lib/pry/prompt.rb +214 -0
- data/pry-0.16.0/lib/pry/pry_class.rb +371 -0
- data/pry-0.16.0/lib/pry/pry_instance.rb +663 -0
- data/pry-0.16.0/lib/pry/repl.rb +326 -0
- data/pry-0.16.0/lib/pry/repl_file_loader.rb +79 -0
- data/pry-0.16.0/lib/pry/ring.rb +89 -0
- data/pry-0.16.0/lib/pry/slop/LICENSE +20 -0
- data/pry-0.16.0/lib/pry/slop/commands.rb +190 -0
- data/pry-0.16.0/lib/pry/slop/option.rb +210 -0
- data/pry-0.16.0/lib/pry/slop.rb +672 -0
- data/pry-0.16.0/lib/pry/syntax_highlighter.rb +26 -0
- data/pry-0.16.0/lib/pry/system_command_handler.rb +17 -0
- data/pry-0.16.0/lib/pry/testable/evalable.rb +24 -0
- data/pry-0.16.0/lib/pry/testable/mockable.rb +22 -0
- data/pry-0.16.0/lib/pry/testable/pry_tester.rb +88 -0
- data/pry-0.16.0/lib/pry/testable/utility.rb +34 -0
- data/pry-0.16.0/lib/pry/testable/variables.rb +52 -0
- data/pry-0.16.0/lib/pry/testable.rb +68 -0
- data/pry-0.16.0/lib/pry/version.rb +5 -0
- data/pry-0.16.0/lib/pry/warning.rb +20 -0
- data/pry-0.16.0/lib/pry/wrapped_module/candidate.rb +145 -0
- data/pry-0.16.0/lib/pry/wrapped_module.rb +382 -0
- data/pry-0.16.0/lib/pry.rb +148 -0
- data/super-smart-mod.gemspec +12 -0
- metadata +182 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
Pry::Commands.instance_eval do
|
|
5
|
+
command(%r{!s/(.*?)/(.*?)}, "") do |source, dest|
|
|
6
|
+
eval_string.gsub!(/#{source}/) { dest }
|
|
7
|
+
run "show-input"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
command "east-coker", "" do
|
|
11
|
+
txt = %(
|
|
12
|
+
--
|
|
13
|
+
Now the light falls
|
|
14
|
+
Across the open field, leaving the deep lane
|
|
15
|
+
Shuttered with branches, dark in the afternoon,
|
|
16
|
+
Where you lean against a bank while a van passes,
|
|
17
|
+
And the deep lane insists on the direction
|
|
18
|
+
Into the village, in the electric heat
|
|
19
|
+
Hypnotised. In a warm haze the sultry light
|
|
20
|
+
Is absorbed, not refracted, by grey stone.
|
|
21
|
+
The dahlias sleep in the empty silence.
|
|
22
|
+
Wait for the early owl.
|
|
23
|
+
-- T.S Eliot
|
|
24
|
+
)
|
|
25
|
+
output.puts txt
|
|
26
|
+
txt
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
command "cohen-poem", "" do
|
|
30
|
+
txt = %(
|
|
31
|
+
--
|
|
32
|
+
When this American woman,
|
|
33
|
+
whose thighs are bound in casual red cloth,
|
|
34
|
+
comes thundering past my sitting place
|
|
35
|
+
like a forest-burning Mongol tribe,
|
|
36
|
+
the city is ravished
|
|
37
|
+
and brittle buildings of a hundred years
|
|
38
|
+
splash into the street;
|
|
39
|
+
and my eyes are burnt
|
|
40
|
+
for the embroidered Chinese girls,
|
|
41
|
+
already old,
|
|
42
|
+
and so small between the thin pines
|
|
43
|
+
on these enormous landscapes,
|
|
44
|
+
that if you turn your head
|
|
45
|
+
they are lost for hours.
|
|
46
|
+
-- Leonard Cohen
|
|
47
|
+
)
|
|
48
|
+
output.puts txt
|
|
49
|
+
txt
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
command "pessoa-poem", "" do
|
|
53
|
+
output.puts <<-TEXT
|
|
54
|
+
--
|
|
55
|
+
I've gone to bed with every feeling,
|
|
56
|
+
I've been the pimp of every emotion,
|
|
57
|
+
All felt sensations have bought me drinks,
|
|
58
|
+
I've traded glances with every motive for every act,
|
|
59
|
+
I've held hands with every urge to depart,
|
|
60
|
+
..
|
|
61
|
+
Rage, foam, the vastness that doesn't fit in my handkerchief,
|
|
62
|
+
The dog in heat howling in the night,
|
|
63
|
+
The pond from the farm going in circles around my insomnia,
|
|
64
|
+
The woods as they were, on our late-afternoon walks, the rose,
|
|
65
|
+
The indifferent tuft of hair, the moss, the pines,
|
|
66
|
+
The rage of not containing all this, not retaining all this,
|
|
67
|
+
O abstract hunger for things, impotent libido for moments,
|
|
68
|
+
Intellectual orgy of feeling life!
|
|
69
|
+
-- Fernando Pessoa
|
|
70
|
+
TEXT
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
command "test-ansi", "" do
|
|
74
|
+
prev_color = pry_instance.config.color
|
|
75
|
+
pry_instance.config.color = true
|
|
76
|
+
|
|
77
|
+
picture = unindent <<-'OUTPUT'.gsub(/[[:alpha:]!]/) { |s| red(s) }
|
|
78
|
+
____ _______________________
|
|
79
|
+
/ \ | A W G |
|
|
80
|
+
/ O O \ | N I O N ! |
|
|
81
|
+
| | | S S R I ! |
|
|
82
|
+
\ \__/ / __| I K ! |
|
|
83
|
+
\____/ \________________________|
|
|
84
|
+
OUTPUT
|
|
85
|
+
|
|
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
|
|
92
|
+
|
|
93
|
+
output.puts "\n" * 6
|
|
94
|
+
output.puts picture.lines.map(&:chomp).reverse.join(move_up[1])
|
|
95
|
+
output.puts "\n" * 6
|
|
96
|
+
output.puts "** ENV['TERM'] is #{ENV['TERM']} **\n\n"
|
|
97
|
+
|
|
98
|
+
pry_instance.config.color = prev_color
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Edit
|
|
6
|
+
class ExceptionPatcher
|
|
7
|
+
attr_accessor :pry_instance
|
|
8
|
+
attr_accessor :state
|
|
9
|
+
attr_accessor :file_and_line
|
|
10
|
+
|
|
11
|
+
def initialize(pry_instance, state, exception_file_and_line)
|
|
12
|
+
@pry_instance = pry_instance
|
|
13
|
+
@state = state
|
|
14
|
+
@file_and_line = exception_file_and_line
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# perform the patch
|
|
18
|
+
def perform_patch
|
|
19
|
+
file_name, = file_and_line
|
|
20
|
+
lines = state.dynamical_ex_file || File.read(file_name)
|
|
21
|
+
|
|
22
|
+
source = Pry::Editor.new(pry_instance).edit_tempfile_with_content(lines)
|
|
23
|
+
pry_instance.evaluate_ruby source
|
|
24
|
+
state.dynamical_ex_file = source.split("\n")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Edit
|
|
6
|
+
module FileAndLineLocator
|
|
7
|
+
class << self
|
|
8
|
+
def from_binding(target)
|
|
9
|
+
if target.respond_to?(:source_location)
|
|
10
|
+
target.source_location
|
|
11
|
+
else
|
|
12
|
+
target.eval("[__FILE__, __LINE__]")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def from_code_object(code_object, filename_argument)
|
|
17
|
+
unless File.exist?(code_object.source_file.to_s)
|
|
18
|
+
raise CommandError, "Cannot find a file for #{filename_argument}!"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
[code_object.source_file, code_object.source_line]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def from_exception(exception, backtrace_level)
|
|
25
|
+
raise CommandError, "No exception found." if exception.nil?
|
|
26
|
+
|
|
27
|
+
file_name, line = exception.bt_source_location_for(backtrace_level)
|
|
28
|
+
raise CommandError, "Exception has no associated file." if file_name.nil?
|
|
29
|
+
|
|
30
|
+
if Pry.eval_path == file_name
|
|
31
|
+
raise CommandError, "Cannot edit exceptions raised in REPL."
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
[file_name, line]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# when file and line are passed as a single arg, e.g my_file.rb:30
|
|
38
|
+
def from_filename_argument(filename_argument)
|
|
39
|
+
f = File.expand_path(filename_argument)
|
|
40
|
+
l = f.sub!(/:(\d+)$/, "") ? Regexp.last_match(1).to_i : 1
|
|
41
|
+
[f, l]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
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
|
+
command_options state: %i[dynamical_ex_file]
|
|
26
|
+
|
|
27
|
+
def options(opt)
|
|
28
|
+
opt.on :e, :ex, "Open the file that raised the most recent exception " \
|
|
29
|
+
"(_ex_.file)",
|
|
30
|
+
optional_argument: true, as: Integer
|
|
31
|
+
opt.on :i, :in, "Open a temporary file containing the Nth input " \
|
|
32
|
+
"expression. N may be a range",
|
|
33
|
+
optional_argument: true, as: Range, default: -1..-1
|
|
34
|
+
opt.on :t, :temp, "Open an empty temporary file"
|
|
35
|
+
opt.on :l, :line, "Jump to this line in the opened file",
|
|
36
|
+
argument: true, as: Integer
|
|
37
|
+
opt.on :n, :"no-reload", "Don't automatically reload the edited file"
|
|
38
|
+
opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as " \
|
|
39
|
+
"returned by `whereami`)"
|
|
40
|
+
opt.on :r, :reload, "Reload the edited code immediately (default for " \
|
|
41
|
+
"ruby files)"
|
|
42
|
+
opt.on :p, :patch, "Instead of editing the object's file, try to edit " \
|
|
43
|
+
"in a tempfile and apply as a monkey patch"
|
|
44
|
+
opt.on :m, :method, "Explicitly edit the _current_ method (when " \
|
|
45
|
+
"inside a method context)."
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def process
|
|
49
|
+
if bad_option_combination?
|
|
50
|
+
raise CommandError, "Only one of --ex, --temp, --in, --method and " \
|
|
51
|
+
"FILE may be specified."
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if repl_edit?
|
|
55
|
+
# code defined in pry, eval'd within pry.
|
|
56
|
+
repl_edit
|
|
57
|
+
elsif runtime_patch?
|
|
58
|
+
# patch code without persisting changes, implies future changes are patches
|
|
59
|
+
apply_runtime_patch
|
|
60
|
+
else
|
|
61
|
+
# code stored in actual files, eval'd at top-level
|
|
62
|
+
file_edit
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def repl_edit?
|
|
67
|
+
!opts.present?(:ex) && !opts.present?(:current) && !opts.present?(:method) &&
|
|
68
|
+
filename_argument.empty?
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def repl_edit
|
|
72
|
+
content = Pry::Editor.new(pry_instance).edit_tempfile_with_content(
|
|
73
|
+
initial_temp_file_content,
|
|
74
|
+
initial_temp_file_content.lines.count
|
|
75
|
+
)
|
|
76
|
+
pry_instance.eval_string = content
|
|
77
|
+
Pry.history.push(content)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def file_based_exception?
|
|
81
|
+
opts.present?(:ex) && !opts.present?(:patch)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def runtime_patch?
|
|
85
|
+
!file_based_exception? &&
|
|
86
|
+
(opts.present?(:patch) ||
|
|
87
|
+
previously_patched?(code_object) ||
|
|
88
|
+
pry_method?(code_object))
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def apply_runtime_patch
|
|
92
|
+
if patch_exception?
|
|
93
|
+
ExceptionPatcher.new(
|
|
94
|
+
pry_instance, state, file_and_line_for_current_exception
|
|
95
|
+
).perform_patch
|
|
96
|
+
elsif code_object.is_a?(Pry::Method)
|
|
97
|
+
code_object.redefine(
|
|
98
|
+
Pry::Editor.new(pry_instance).edit_tempfile_with_content(
|
|
99
|
+
code_object.source
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
else
|
|
103
|
+
raise NotImplementedError, "Cannot yet patch #{code_object} objects!"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def ensure_file_name_is_valid(file_name)
|
|
108
|
+
unless file_name
|
|
109
|
+
raise CommandError, "Cannot find a valid file for #{filename_argument}"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
return unless not_a_real_file?(file_name)
|
|
113
|
+
|
|
114
|
+
raise CommandError, "#{file_name} is not a valid file name, cannot edit!"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def file_and_line_for_current_exception
|
|
118
|
+
FileAndLineLocator.from_exception(pry_instance.last_exception, opts[:ex].to_i)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def file_and_line
|
|
122
|
+
file_name, line =
|
|
123
|
+
if opts.present?(:current)
|
|
124
|
+
FileAndLineLocator.from_binding(target)
|
|
125
|
+
elsif opts.present?(:ex)
|
|
126
|
+
file_and_line_for_current_exception
|
|
127
|
+
elsif code_object
|
|
128
|
+
FileAndLineLocator.from_code_object(code_object, filename_argument)
|
|
129
|
+
else
|
|
130
|
+
# when file and line are passed as a single arg, e.g my_file.rb:30
|
|
131
|
+
FileAndLineLocator.from_filename_argument(filename_argument)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
[file_name, opts.present?(:line) ? opts[:l].to_i : line]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def file_edit
|
|
138
|
+
file_name, line = file_and_line
|
|
139
|
+
|
|
140
|
+
ensure_file_name_is_valid(file_name)
|
|
141
|
+
|
|
142
|
+
Pry::Editor.new(pry_instance).invoke_editor(file_name, line, reload?(file_name))
|
|
143
|
+
set_file_and_dir_locals(file_name)
|
|
144
|
+
|
|
145
|
+
return unless reload?(file_name)
|
|
146
|
+
|
|
147
|
+
silence_warnings { load(file_name) }
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def filename_argument
|
|
151
|
+
args.join(' ')
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def code_object
|
|
155
|
+
@code_object ||=
|
|
156
|
+
!probably_a_file?(filename_argument) &&
|
|
157
|
+
Pry::CodeObject.lookup(filename_argument, pry_instance)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def pry_method?(code_object)
|
|
161
|
+
code_object.is_a?(Pry::Method) &&
|
|
162
|
+
code_object.pry_method?
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def previously_patched?(code_object)
|
|
166
|
+
code_object.is_a?(Pry::Method) &&
|
|
167
|
+
Pry::Method::Patcher.code_for(code_object.source_location.first)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def patch_exception?
|
|
171
|
+
opts.present?(:ex) && opts.present?(:patch)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def bad_option_combination?
|
|
175
|
+
[
|
|
176
|
+
opts.present?(:ex), opts.present?(:temp),
|
|
177
|
+
opts.present?(:in), opts.present?(:method),
|
|
178
|
+
!filename_argument.empty?
|
|
179
|
+
].count(true) > 1
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def input_expression
|
|
183
|
+
case opts[:i]
|
|
184
|
+
when Range
|
|
185
|
+
(pry_instance.input_ring[opts[:i]] || []).join
|
|
186
|
+
when Integer
|
|
187
|
+
pry_instance.input_ring[opts[:i]] || ""
|
|
188
|
+
else
|
|
189
|
+
raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def reloadable?
|
|
194
|
+
opts.present?(:reload) || opts.present?(:ex)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def never_reload?
|
|
198
|
+
opts.present?(:'no-reload') || pry_instance.config.disable_auto_reload
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def reload?(file_name = "")
|
|
202
|
+
(reloadable? || file_name.end_with?(".rb")) && !never_reload?
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def initial_temp_file_content
|
|
206
|
+
if opts.present?(:temp)
|
|
207
|
+
""
|
|
208
|
+
elsif opts.present?(:in)
|
|
209
|
+
input_expression
|
|
210
|
+
elsif eval_string.strip != ""
|
|
211
|
+
eval_string
|
|
212
|
+
else
|
|
213
|
+
pry_instance.input_ring.to_a.reverse_each.find { |x| x && x.strip != "" } || ""
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def probably_a_file?(str)
|
|
218
|
+
[".rb", ".c", ".py", ".yml", ".gemspec"].include?(File.extname(str)) ||
|
|
219
|
+
str =~ %r{/|\\}
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
Pry::Commands.add_command(Pry::Command::Edit)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Exit < Pry::ClassCommand
|
|
6
|
+
match 'exit'
|
|
7
|
+
group 'Navigating Pry'
|
|
8
|
+
description 'Pop the previous binding.'
|
|
9
|
+
command_options keep_retval: true
|
|
10
|
+
|
|
11
|
+
banner <<-'BANNER'
|
|
12
|
+
Usage: exit [OPTIONS] [--help]
|
|
13
|
+
Aliases: quit
|
|
14
|
+
|
|
15
|
+
Pop the previous binding (does NOT exit program). It can be useful to exit a
|
|
16
|
+
context with a user-provided value. For instance an exit value can be used to
|
|
17
|
+
determine program flow.
|
|
18
|
+
|
|
19
|
+
exit "pry this"
|
|
20
|
+
exit
|
|
21
|
+
|
|
22
|
+
https://github.com/pry/pry/wiki/State-navigation#wiki-Exit_with_value
|
|
23
|
+
BANNER
|
|
24
|
+
|
|
25
|
+
def process
|
|
26
|
+
if pry_instance.binding_stack.one?
|
|
27
|
+
pry_instance.run_command "exit-all #{arg_string}"
|
|
28
|
+
else
|
|
29
|
+
# otherwise just pop a binding and return user supplied value
|
|
30
|
+
process_pop_and_return
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def process_pop_and_return
|
|
35
|
+
popped_object = pry_instance.binding_stack.pop.eval('self')
|
|
36
|
+
|
|
37
|
+
# return a user-specified value if given otherwise return the object
|
|
38
|
+
return target.eval(arg_string) unless arg_string.empty?
|
|
39
|
+
|
|
40
|
+
popped_object
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
Pry::Commands.add_command(Pry::Command::Exit)
|
|
45
|
+
Pry::Commands.alias_command 'quit', 'exit'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class ExitAll < Pry::ClassCommand
|
|
6
|
+
match 'exit-all'
|
|
7
|
+
group 'Navigating Pry'
|
|
8
|
+
description 'End the current Pry session.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Usage: exit-all [--help]
|
|
12
|
+
Aliases: !!@
|
|
13
|
+
|
|
14
|
+
End the current Pry session (popping all bindings and returning to caller).
|
|
15
|
+
Accepts optional return value.
|
|
16
|
+
BANNER
|
|
17
|
+
|
|
18
|
+
def process
|
|
19
|
+
# calculate user-given value
|
|
20
|
+
exit_value = target.eval(arg_string)
|
|
21
|
+
|
|
22
|
+
# clear the binding stack
|
|
23
|
+
pry_instance.binding_stack.clear
|
|
24
|
+
|
|
25
|
+
# break out of the repl loop
|
|
26
|
+
throw(:breakout, exit_value)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Pry::Commands.add_command(Pry::Command::ExitAll)
|
|
31
|
+
Pry::Commands.alias_command '!!@', 'exit-all'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class ExitProgram < Pry::ClassCommand
|
|
6
|
+
match 'exit-program'
|
|
7
|
+
group 'Navigating Pry'
|
|
8
|
+
description 'End the current program.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Usage: exit-program [--help]
|
|
12
|
+
Aliases: quit-program
|
|
13
|
+
!!!
|
|
14
|
+
|
|
15
|
+
End the current program.
|
|
16
|
+
BANNER
|
|
17
|
+
|
|
18
|
+
def process
|
|
19
|
+
Kernel.exit target.eval(arg_string).to_i
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
Pry::Commands.add_command(Pry::Command::ExitProgram)
|
|
24
|
+
Pry::Commands.alias_command 'quit-program', 'exit-program'
|
|
25
|
+
Pry::Commands.alias_command '!!!', 'exit-program'
|
|
26
|
+
end
|
|
27
|
+
end
|