pry 0.10.2-i386-mingw32 → 1.0.0.pre1-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +2 -0
- data/.gitignore +16 -0
- data/.travis.yml +21 -0
- data/.yardopts +3 -0
- data/CHANGELOG +503 -0
- data/CONTRIBUTORS +55 -0
- data/Gemfile +9 -0
- data/Guardfile +62 -0
- data/LICENSE +2 -2
- data/{README.md → README.markdown} +31 -37
- data/Rakefile +144 -0
- data/TODO +117 -0
- data/lib/pry.rb +146 -33
- data/lib/pry/cli.rb +13 -35
- data/lib/pry/code.rb +63 -24
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +21 -40
- data/lib/pry/command.rb +6 -9
- data/lib/pry/command_set.rb +37 -80
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +1 -1
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +2 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
- data/lib/pry/commands/cat/exception_formatter.rb +7 -6
- data/lib/pry/commands/cat/file_formatter.rb +32 -15
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cd.rb +3 -14
- data/lib/pry/commands/code_collector.rb +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +22 -10
- data/lib/pry/commands/edit/exception_patcher.rb +1 -1
- data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
- data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
- data/lib/pry/commands/find_method.rb +22 -16
- data/lib/pry/commands/gem_install.rb +2 -5
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +11 -10
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +5 -24
- data/lib/pry/commands/ls.rb +287 -56
- data/lib/pry/commands/play.rb +10 -44
- data/lib/pry/commands/pry_backtrace.rb +2 -1
- data/lib/pry/commands/raise_up.rb +1 -1
- data/lib/pry/commands/reload_code.rb +15 -31
- data/lib/pry/commands/ri.rb +3 -7
- data/lib/pry/commands/shell_command.rb +12 -17
- data/lib/pry/commands/shell_mode.rb +2 -2
- data/lib/pry/commands/show_doc.rb +0 -5
- data/lib/pry/commands/show_info.rb +10 -11
- data/lib/pry/commands/show_source.rb +3 -15
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +4 -8
- data/lib/pry/commands/whereami.rb +10 -18
- data/lib/pry/completion.rb +293 -0
- data/lib/pry/config.rb +233 -20
- data/lib/pry/core_extensions.rb +19 -29
- data/lib/pry/custom_completions.rb +6 -0
- data/lib/pry/editor.rb +103 -109
- data/lib/pry/helpers/base_helpers.rb +109 -22
- data/lib/pry/helpers/command_helpers.rb +8 -10
- data/lib/pry/helpers/documentation_helpers.rb +2 -1
- data/lib/pry/helpers/text.rb +5 -4
- data/lib/pry/history.rb +10 -21
- data/lib/pry/history_array.rb +0 -5
- data/lib/pry/hooks.rb +29 -9
- data/lib/pry/indent.rb +10 -5
- data/lib/pry/method.rb +86 -81
- data/lib/pry/method/weird_method_locator.rb +2 -4
- data/lib/pry/module_candidate.rb +14 -5
- data/lib/pry/pager.rb +48 -193
- data/lib/pry/plugins.rb +2 -2
- data/lib/pry/pry_class.rb +193 -104
- data/lib/pry/pry_instance.rb +154 -152
- data/lib/pry/rbx_method.rb +13 -0
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +14 -17
- data/lib/pry/repl_file_loader.rb +3 -8
- data/lib/pry/rubygem.rb +3 -3
- data/lib/pry/terminal.rb +3 -4
- data/lib/pry/test/helper.rb +11 -6
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +56 -49
- data/man/pry.1 +195 -0
- data/man/pry.1.html +204 -0
- data/man/pry.1.ronn +141 -0
- data/pry.gemspec +31 -0
- data/spec/Procfile +3 -0
- data/spec/cli_spec.rb +78 -0
- data/spec/code_object_spec.rb +277 -0
- data/spec/code_spec.rb +219 -0
- data/spec/command_helpers_spec.rb +29 -0
- data/spec/command_integration_spec.rb +562 -0
- data/spec/command_set_spec.rb +627 -0
- data/spec/command_spec.rb +821 -0
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +18 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +725 -0
- data/spec/commands/exit_all_spec.rb +27 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +28 -0
- data/spec/commands/find_method_spec.rb +70 -0
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +79 -0
- data/spec/commands/help_spec.rb +56 -0
- data/spec/commands/hist_spec.rb +172 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +189 -0
- data/spec/commands/play_spec.rb +136 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +488 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +760 -0
- data/spec/commands/whereami_spec.rb +203 -0
- data/spec/completion_spec.rb +221 -0
- data/spec/control_d_handler_spec.rb +62 -0
- data/spec/documentation_helper_spec.rb +73 -0
- data/spec/editor_spec.rb +79 -0
- data/spec/exception_whitelist_spec.rb +21 -0
- data/spec/fixtures/candidate_helper1.rb +11 -0
- data/spec/fixtures/candidate_helper2.rb +8 -0
- data/spec/fixtures/example.erb +5 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/spec/fixtures/testlinkrc +2 -0
- data/spec/fixtures/testrc +2 -0
- data/spec/fixtures/testrcbad +2 -0
- data/spec/fixtures/whereami_helper.rb +6 -0
- data/spec/helper.rb +35 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +44 -0
- data/spec/helpers/repl_tester.rb +112 -0
- data/spec/helpers/table_spec.rb +105 -0
- data/spec/history_array_spec.rb +67 -0
- data/spec/hooks_spec.rb +522 -0
- data/spec/indent_spec.rb +301 -0
- data/spec/method_spec.rb +482 -0
- data/spec/prompt_spec.rb +61 -0
- data/spec/pry_defaults_spec.rb +420 -0
- data/spec/pry_history_spec.rb +69 -0
- data/spec/pry_output_spec.rb +95 -0
- data/spec/pry_repl_spec.rb +86 -0
- data/spec/pry_spec.rb +394 -0
- data/spec/pryrc_spec.rb +97 -0
- data/spec/run_command_spec.rb +25 -0
- data/spec/sticky_locals_spec.rb +147 -0
- data/spec/syntax_checking_spec.rb +81 -0
- data/spec/wrapped_module_spec.rb +261 -0
- data/wiki/Customizing-pry.md +397 -0
- data/wiki/Home.md +4 -0
- metadata +272 -61
- checksums.yaml +0 -7
- data/CHANGELOG.md +0 -714
- data/lib/pry/code/code_file.rb +0 -103
- data/lib/pry/color_printer.rb +0 -55
- data/lib/pry/commands/change_inspector.rb +0 -27
- data/lib/pry/commands/change_prompt.rb +0 -26
- data/lib/pry/commands/list_inspectors.rb +0 -35
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/ls/constants.rb +0 -47
- data/lib/pry/commands/ls/formatter.rb +0 -49
- data/lib/pry/commands/ls/globals.rb +0 -48
- data/lib/pry/commands/ls/grep.rb +0 -21
- data/lib/pry/commands/ls/instance_vars.rb +0 -39
- data/lib/pry/commands/ls/interrogatable.rb +0 -18
- data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
- data/lib/pry/commands/ls/local_names.rb +0 -35
- data/lib/pry/commands/ls/local_vars.rb +0 -39
- data/lib/pry/commands/ls/ls_entity.rb +0 -70
- data/lib/pry/commands/ls/methods.rb +0 -57
- data/lib/pry/commands/ls/methods_helper.rb +0 -46
- data/lib/pry/commands/ls/self_methods.rb +0 -32
- data/lib/pry/commands/watch_expression.rb +0 -105
- data/lib/pry/commands/watch_expression/expression.rb +0 -38
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/exceptions.rb +0 -78
- data/lib/pry/input_completer.rb +0 -242
- data/lib/pry/input_lock.rb +0 -132
- data/lib/pry/inspector.rb +0 -27
- data/lib/pry/last_exception.rb +0 -61
- data/lib/pry/object_path.rb +0 -82
- data/lib/pry/output.rb +0 -50
- data/lib/pry/prompt.rb +0 -26
data/lib/pry/commands.rb
CHANGED
data/lib/pry/commands/bang.rb
CHANGED
data/lib/pry/commands/cat.rb
CHANGED
@@ -41,20 +41,11 @@ class Pry
|
|
41
41
|
FileFormatter.new(args.first, _pry_, opts).format
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
stagger_output(output)
|
45
45
|
end
|
46
46
|
|
47
47
|
def complete(search)
|
48
|
-
super
|
49
|
-
end
|
50
|
-
|
51
|
-
def load_path_completions
|
52
|
-
$LOAD_PATH.flat_map do |path|
|
53
|
-
Dir[path + '/**/*'].map { |f|
|
54
|
-
next if File.directory?(f)
|
55
|
-
f.sub!(path + '/', '')
|
56
|
-
}
|
57
|
-
end
|
48
|
+
super + Bond::Rc.files(search.split(" ").last || '')
|
58
49
|
end
|
59
50
|
end
|
60
51
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Pry
|
2
2
|
class Command::Cat
|
3
3
|
class ExceptionFormatter < AbstractFormatter
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
attr_accessor :ex
|
5
|
+
attr_accessor :opts
|
6
|
+
attr_accessor :_pry_
|
7
7
|
|
8
8
|
def initialize(exception, _pry_, opts)
|
9
9
|
@ex = exception
|
@@ -16,14 +16,14 @@ class Pry
|
|
16
16
|
set_file_and_dir_locals(backtrace_file, _pry_, _pry_.current_context)
|
17
17
|
code = decorate(Pry::Code.from_file(backtrace_file).
|
18
18
|
between(*start_and_end_line_for_code_window).
|
19
|
-
with_marker(backtrace_line))
|
19
|
+
with_marker(backtrace_line)).to_s
|
20
20
|
"#{header}#{code}"
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def code_window_size
|
26
|
-
|
26
|
+
Pry.config.default_window_size || 5
|
27
27
|
end
|
28
28
|
|
29
29
|
def backtrace_level
|
@@ -44,7 +44,8 @@ class Pry
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def backtrace_file
|
47
|
-
Array(ex.bt_source_location_for(backtrace_level)).first
|
47
|
+
file = Array(ex.bt_source_location_for(backtrace_level)).first
|
48
|
+
(file && RbxPath.is_core_path?(file)) ? RbxPath.convert_path_to_full(file) : file
|
48
49
|
end
|
49
50
|
|
50
51
|
def backtrace_line
|
@@ -1,32 +1,31 @@
|
|
1
1
|
class Pry
|
2
2
|
class Command::Cat
|
3
3
|
class FileFormatter < AbstractFormatter
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
attr_accessor :file_with_embedded_line
|
5
|
+
attr_accessor :opts
|
6
|
+
attr_accessor :_pry_
|
7
7
|
|
8
8
|
def initialize(file_with_embedded_line, _pry_, opts)
|
9
9
|
@file_with_embedded_line = file_with_embedded_line
|
10
10
|
@opts = opts
|
11
11
|
@_pry_ = _pry_
|
12
|
-
@code_from_file = Pry::Code.from_file(file_name)
|
13
12
|
end
|
14
13
|
|
15
14
|
def format
|
16
15
|
raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line
|
17
16
|
|
18
17
|
set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
|
19
|
-
decorate(
|
18
|
+
decorate(Pry::Code.from_file(file_name))
|
20
19
|
end
|
21
20
|
|
21
|
+
private
|
22
|
+
|
22
23
|
def file_and_line
|
23
|
-
file_name, line_num = file_with_embedded_line.split(
|
24
|
+
file_name, line_num = file_with_embedded_line.split(':')
|
24
25
|
|
25
|
-
[file_name, line_num ? line_num.to_i : nil]
|
26
|
+
[File.expand_path(file_name), line_num ? line_num.to_i : nil]
|
26
27
|
end
|
27
28
|
|
28
|
-
private
|
29
|
-
|
30
29
|
def file_name
|
31
30
|
file_and_line.first
|
32
31
|
end
|
@@ -36,7 +35,7 @@ class Pry
|
|
36
35
|
end
|
37
36
|
|
38
37
|
def code_window_size
|
39
|
-
|
38
|
+
Pry.config.default_window_size || 7
|
40
39
|
end
|
41
40
|
|
42
41
|
def decorate(content)
|
@@ -48,18 +47,36 @@ class Pry
|
|
48
47
|
end
|
49
48
|
|
50
49
|
def detect_code_type_from_file(file_name)
|
51
|
-
|
50
|
+
name, ext = File.basename(file_name).split('.', 2)
|
52
51
|
|
53
|
-
if
|
54
|
-
|
52
|
+
if ext
|
53
|
+
case ext
|
54
|
+
when "py"
|
55
|
+
:python
|
56
|
+
when "rb", "gemspec", "rakefile", "ru", "pryrc", "irbrc"
|
57
|
+
:ruby
|
58
|
+
when "js"
|
59
|
+
return :javascript
|
60
|
+
when "yml", "prytheme"
|
61
|
+
:yaml
|
62
|
+
when "groovy"
|
63
|
+
:groovy
|
64
|
+
when "c"
|
65
|
+
:c
|
66
|
+
when "cpp"
|
67
|
+
:cpp
|
68
|
+
when "java"
|
69
|
+
:java
|
70
|
+
else
|
71
|
+
:text
|
72
|
+
end
|
73
|
+
else
|
55
74
|
case name
|
56
75
|
when "Rakefile", "Gemfile"
|
57
76
|
:ruby
|
58
77
|
else
|
59
78
|
:text
|
60
79
|
end
|
61
|
-
else
|
62
|
-
code_type
|
63
80
|
end
|
64
81
|
end
|
65
82
|
end
|
data/lib/pry/commands/cd.rb
CHANGED
@@ -9,7 +9,7 @@ class Pry
|
|
9
9
|
|
10
10
|
Move into new context (object or scope). As in UNIX shells use `cd ..` to go
|
11
11
|
back, `cd /` to return to Pry top-level and `cd -` to toggle between last two
|
12
|
-
scopes. Complex syntax (e.g `cd ../@x
|
12
|
+
scopes. Complex syntax (e.g `cd ../@x/y`) also supported.
|
13
13
|
|
14
14
|
cd @x
|
15
15
|
cd ..
|
@@ -21,19 +21,8 @@ class Pry
|
|
21
21
|
|
22
22
|
def process
|
23
23
|
state.old_stack ||= []
|
24
|
-
|
25
|
-
|
26
|
-
unless state.old_stack.empty?
|
27
|
-
_pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack
|
28
|
-
end
|
29
|
-
else
|
30
|
-
stack = ObjectPath.new(arg_string, _pry_.binding_stack).resolve
|
31
|
-
|
32
|
-
if stack && stack != _pry_.binding_stack
|
33
|
-
state.old_stack = _pry_.binding_stack
|
34
|
-
_pry_.binding_stack = stack
|
35
|
-
end
|
36
|
-
end
|
24
|
+
stack, state.old_stack = context_from_object_path(arg_string, _pry_, state.old_stack)
|
25
|
+
_pry_.binding_stack = stack if stack
|
37
26
|
end
|
38
27
|
end
|
39
28
|
|
@@ -2,9 +2,9 @@ class Pry
|
|
2
2
|
class Command::CodeCollector
|
3
3
|
include Helpers::CommandHelpers
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
attr_accessor :args
|
6
|
+
attr_accessor :opts
|
7
|
+
attr_accessor :_pry_
|
8
8
|
|
9
9
|
# The name of the explicitly given file (if any).
|
10
10
|
attr_accessor :file
|
@@ -91,7 +91,7 @@ class Pry
|
|
91
91
|
# @return [String]
|
92
92
|
def pry_output_content
|
93
93
|
pry_array_content_as_string(_pry_.output_array, self.class.output_result_ranges) do |v|
|
94
|
-
|
94
|
+
Pry.config.gist.inspecter.call(v)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -83,8 +83,8 @@ TEXT
|
|
83
83
|
end
|
84
84
|
|
85
85
|
command "test-ansi", "" do
|
86
|
-
prev_color =
|
87
|
-
|
86
|
+
prev_color = Pry.color
|
87
|
+
Pry.color = true
|
88
88
|
|
89
89
|
picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| text.red(s) }
|
90
90
|
____ _______________________
|
@@ -106,7 +106,7 @@ TEXT
|
|
106
106
|
output.puts "\n" * 6
|
107
107
|
output.puts "** ENV['TERM'] is #{ENV['TERM']} **\n\n"
|
108
108
|
|
109
|
-
|
109
|
+
Pry.color = prev_color
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
data/lib/pry/commands/edit.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class Pry
|
2
2
|
class Command::Edit < Pry::ClassCommand
|
3
|
+
require 'pry/commands/edit/method_patcher'
|
3
4
|
require 'pry/commands/edit/exception_patcher'
|
4
5
|
require 'pry/commands/edit/file_and_line_locator'
|
5
6
|
|
@@ -12,7 +13,7 @@ class Pry
|
|
12
13
|
|
13
14
|
Open a text editor. When no FILE is given, edits the pry input buffer.
|
14
15
|
When a method/module/command is given, the code is opened in an editor.
|
15
|
-
Ensure `Pry.config.editor`
|
16
|
+
Ensure `Pry.config.editor` is set to your editor of choice.
|
16
17
|
|
17
18
|
edit sample.rb edit -p MyClass#my_method
|
18
19
|
edit sample.rb --line 105 edit MyClass
|
@@ -30,7 +31,7 @@ class Pry
|
|
30
31
|
opt.on :t, :temp, "Open an empty temporary file"
|
31
32
|
opt.on :l, :line, "Jump to this line in the opened file",
|
32
33
|
:argument => true, :as => Integer
|
33
|
-
opt.on :n, :"no-reload", "Don't automatically reload the edited
|
34
|
+
opt.on :n, :"no-reload", "Don't automatically reload the edited code"
|
34
35
|
opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as returned by `whereami`)"
|
35
36
|
opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)"
|
36
37
|
opt.on :p, :patch, "Instead of editing the object's file, try to edit in a tempfile and apply as a monkey patch"
|
@@ -60,10 +61,12 @@ class Pry
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def repl_edit
|
63
|
-
content = Pry::Editor.
|
64
|
+
content = Pry::Editor.edit_tempfile_with_content(initial_temp_file_content,
|
64
65
|
initial_temp_file_content.lines.count)
|
65
|
-
|
66
|
-
|
66
|
+
if repl_reload?
|
67
|
+
silence_warnings do
|
68
|
+
eval_string.replace content
|
69
|
+
end
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
@@ -80,7 +83,7 @@ class Pry
|
|
80
83
|
ExceptionPatcher.new(_pry_, state, file_and_line_for_current_exception).perform_patch
|
81
84
|
else
|
82
85
|
if code_object.is_a?(Pry::Method)
|
83
|
-
|
86
|
+
MethodPatcher.new(_pry_, code_object).perform_patch
|
84
87
|
else
|
85
88
|
raise NotImplementedError, "Cannot yet patch #{code_object} objects!"
|
86
89
|
end
|
@@ -116,12 +119,12 @@ class Pry
|
|
116
119
|
|
117
120
|
ensure_file_name_is_valid(file_name)
|
118
121
|
|
119
|
-
Pry::Editor.
|
122
|
+
Pry::Editor.invoke_editor(file_name, line, reload?(file_name))
|
120
123
|
set_file_and_dir_locals(file_name)
|
121
124
|
|
122
125
|
if reload?(file_name)
|
123
126
|
silence_warnings do
|
124
|
-
|
127
|
+
TOPLEVEL_BINDING.eval(File.read(file_name), file_name)
|
125
128
|
end
|
126
129
|
end
|
127
130
|
end
|
@@ -165,7 +168,12 @@ class Pry
|
|
165
168
|
end
|
166
169
|
|
167
170
|
def never_reload?
|
168
|
-
opts.present?(:'no-reload') ||
|
171
|
+
opts.present?(:'no-reload') || Pry.config.disable_auto_reload
|
172
|
+
end
|
173
|
+
|
174
|
+
# conditions much less strict than for reload? (which is for file-based reloads)
|
175
|
+
def repl_reload?
|
176
|
+
!never_reload?
|
169
177
|
end
|
170
178
|
|
171
179
|
def reload?(file_name="")
|
@@ -186,9 +194,13 @@ class Pry
|
|
186
194
|
end
|
187
195
|
|
188
196
|
def probably_a_file?(str)
|
189
|
-
[".rb", ".c", ".py", ".yml", ".gemspec"].include?
|
197
|
+
[".rb", ".c", ".py", ".yml", ".gemspec"].include? File.extname(str) ||
|
190
198
|
str =~ /\/|\\/
|
191
199
|
end
|
200
|
+
|
201
|
+
def complete(search)
|
202
|
+
super + Bond::Rc.files(search.split(" ").last || '')
|
203
|
+
end
|
192
204
|
end
|
193
205
|
|
194
206
|
Pry::Commands.add_command(Pry::Command::Edit)
|
@@ -16,7 +16,7 @@ class Pry
|
|
16
16
|
file_name, _ = file_and_line
|
17
17
|
lines = state.dynamical_ex_file || File.read(file_name)
|
18
18
|
|
19
|
-
source = Pry::Editor.
|
19
|
+
source = Pry::Editor.edit_tempfile_with_content(lines)
|
20
20
|
_pry_.evaluate_ruby source
|
21
21
|
state.dynamical_ex_file = source.split("\n")
|
22
22
|
end
|
@@ -21,6 +21,8 @@ class Pry
|
|
21
21
|
raise CommandError, "Exception has no associated file." if file_name.nil?
|
22
22
|
raise CommandError, "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name
|
23
23
|
|
24
|
+
file_name = RbxPath.convert_path_to_full(file_name) if RbxPath.is_core_path?(file_name)
|
25
|
+
|
24
26
|
[file_name, line]
|
25
27
|
end
|
26
28
|
|
@@ -1,38 +1,37 @@
|
|
1
1
|
class Pry
|
2
|
-
class
|
3
|
-
class
|
4
|
-
attr_accessor :
|
2
|
+
class Command::Edit
|
3
|
+
class MethodPatcher
|
4
|
+
attr_accessor :_pry_
|
5
|
+
attr_accessor :code_object
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@method = method
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.code_for(filename)
|
13
|
-
@@source_cache[filename]
|
7
|
+
def initialize(_pry_, code_object)
|
8
|
+
@_pry_ = _pry_
|
9
|
+
@code_object = code_object
|
14
10
|
end
|
15
11
|
|
16
12
|
# perform the patch
|
17
|
-
def
|
18
|
-
if
|
13
|
+
def perform_patch
|
14
|
+
if code_object.alias?
|
19
15
|
with_method_transaction do
|
20
|
-
|
16
|
+
_pry_.evaluate_ruby patched_code
|
21
17
|
end
|
22
18
|
else
|
23
|
-
|
19
|
+
_pry_.evaluate_ruby patched_code
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
23
|
private
|
28
24
|
|
29
|
-
def
|
30
|
-
|
31
|
-
TOPLEVEL_BINDING.eval wrap(source), cache_key
|
25
|
+
def patched_code
|
26
|
+
@patched_code ||= wrap(Pry::Editor.edit_tempfile_with_content(adjusted_lines))
|
32
27
|
end
|
33
28
|
|
34
|
-
|
35
|
-
|
29
|
+
# The method code adjusted so that the first line is rewritten
|
30
|
+
# so that def self.foo --> def foo
|
31
|
+
def adjusted_lines
|
32
|
+
lines = code_object.source.lines.to_a
|
33
|
+
lines[0] = definition_line_for_owner(lines.first)
|
34
|
+
lines
|
36
35
|
end
|
37
36
|
|
38
37
|
# Run some code ensuring that at the end target#meth_name will not have changed.
|
@@ -46,17 +45,17 @@ class Pry
|
|
46
45
|
# @param [Module] target The owner of the method
|
47
46
|
|
48
47
|
def with_method_transaction
|
49
|
-
temp_name = "__pry_#{
|
50
|
-
|
51
|
-
|
52
|
-
alias_method temp_name,
|
48
|
+
temp_name = "__pry_#{code_object.original_name}__"
|
49
|
+
co = code_object
|
50
|
+
code_object.owner.class_eval do
|
51
|
+
alias_method temp_name, co.original_name
|
53
52
|
yield
|
54
|
-
alias_method
|
55
|
-
alias_method
|
53
|
+
alias_method co.name, co.original_name
|
54
|
+
alias_method co.original_name, temp_name
|
56
55
|
end
|
57
56
|
|
58
57
|
ensure
|
59
|
-
|
58
|
+
co.send(:remove_method, temp_name) rescue nil
|
60
59
|
end
|
61
60
|
|
62
61
|
# Update the definition line so that it can be eval'd directly on the Method's
|
@@ -69,13 +68,13 @@ class Pry
|
|
69
68
|
# This is necessarily done by String manipulation because we can't find out what
|
70
69
|
# syntax is needed for the argument list by ruby-level introspection.
|
71
70
|
#
|
72
|
-
# @param
|
73
|
-
# @return
|
74
|
-
def
|
75
|
-
if line =~
|
76
|
-
"def #{
|
71
|
+
# @param String The original definition line. e.g. def self.foo(bar, baz=1)
|
72
|
+
# @return String The new definition line. e.g. def foo(bar, baz=1)
|
73
|
+
def definition_line_for_owner(line)
|
74
|
+
if line =~ /^def (?:.*?\.)?#{Regexp.escape(code_object.original_name)}(?=[\(\s;]|$)/
|
75
|
+
"def #{code_object.original_name}#{$'}"
|
77
76
|
else
|
78
|
-
raise CommandError, "Could not find original `def #{
|
77
|
+
raise CommandError, "Could not find original `def #{code_object.original_name}` line to patch."
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
@@ -88,17 +87,15 @@ class Pry
|
|
88
87
|
|
89
88
|
# Update the source code so that when it has the right owner when eval'd.
|
90
89
|
#
|
91
|
-
# This (combined with
|
90
|
+
# This (combined with definition_line_for_owner) is backup for the case that
|
92
91
|
# wrap_for_nesting fails, to ensure that the method will stil be defined in
|
93
92
|
# the correct place.
|
94
93
|
#
|
95
94
|
# @param [String] source The source to wrap
|
96
95
|
# @return [String]
|
97
96
|
def wrap_for_owner(source)
|
98
|
-
Pry.current[:pry_owner] =
|
99
|
-
|
100
|
-
visibility_fix = "#{method.visibility.to_s} #{method.name.to_sym.inspect}"
|
101
|
-
"Pry.current[:pry_owner].class_eval do; #{owner_source}\n#{visibility_fix}\nend"
|
97
|
+
Pry.current[:pry_owner] = code_object.owner
|
98
|
+
"Pry.current[:pry_owner].class_eval do\n#{source}\nend"
|
102
99
|
end
|
103
100
|
|
104
101
|
# Update the new source code to have the correct Module.nesting.
|
@@ -114,9 +111,9 @@ class Pry
|
|
114
111
|
# @param [String] source The source to wrap.
|
115
112
|
# @return [String]
|
116
113
|
def wrap_for_nesting(source)
|
117
|
-
nesting = Pry::Code.from_file(
|
114
|
+
nesting = Pry::Code.from_file(code_object.source_file).nesting_at(code_object.source_line)
|
118
115
|
|
119
|
-
(nesting + [source] + nesting.map{ "end" } + [""]).join("
|
116
|
+
(nesting + [source] + nesting.map{ "end" } + [""]).join("\n")
|
120
117
|
rescue Pry::Indent::UnparseableNestingError
|
121
118
|
source
|
122
119
|
end
|