pry 0.12.2-java → 0.13.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +110 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry.rb +133 -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 +40 -31
- data/lib/pry/code.rb +39 -27
- 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 +24 -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 +81 -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 +109 -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 +311 -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 +41 -42
- data/lib/pry/plugins.rb +25 -8
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -98
- 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 +31 -30
- 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/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
data/lib/pry/cli.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
1
5
|
class Pry
|
2
6
|
# Manage the processing of command line options
|
3
7
|
class CLI
|
@@ -33,9 +37,7 @@ class Pry
|
|
33
37
|
|
34
38
|
# Bring in options defined in plugins
|
35
39
|
def add_plugin_options
|
36
|
-
Pry.plugins.values.each
|
37
|
-
plugin.load_cli_options
|
38
|
-
end
|
40
|
+
Pry.plugins.values.each(&:load_cli_options)
|
39
41
|
|
40
42
|
self
|
41
43
|
end
|
@@ -56,14 +58,22 @@ class Pry
|
|
56
58
|
|
57
59
|
def parse_options(args = ARGV)
|
58
60
|
unless options
|
59
|
-
raise NoOptionsError,
|
61
|
+
raise NoOptionsError,
|
62
|
+
"No command line options defined! Use Pry::CLI.add_options to " \
|
63
|
+
"add command line options."
|
60
64
|
end
|
61
65
|
|
62
|
-
|
66
|
+
@pass_argv = args.index { |cli_arg| %w[- --].include?(cli_arg) }
|
67
|
+
if @pass_argv
|
68
|
+
slop_args = args[0...@pass_argv]
|
69
|
+
self.input_args = args.replace(args[@pass_argv + 1..-1])
|
70
|
+
else
|
71
|
+
self.input_args = slop_args = args
|
72
|
+
end
|
63
73
|
|
64
74
|
begin
|
65
75
|
opts = Pry::Slop.parse!(
|
66
|
-
|
76
|
+
slop_args,
|
67
77
|
help: true,
|
68
78
|
multiple_switches: false,
|
69
79
|
strict: true,
|
@@ -72,22 +82,20 @@ class Pry
|
|
72
82
|
rescue Pry::Slop::InvalidOptionError
|
73
83
|
# Display help message on unknown switches and exit.
|
74
84
|
puts Pry::Slop.new(&options)
|
75
|
-
exit
|
85
|
+
Kernel.exit
|
76
86
|
end
|
77
87
|
|
78
88
|
Pry.initial_session_setup
|
79
89
|
Pry.final_session_setup
|
80
90
|
|
81
91
|
# Option processors are optional.
|
82
|
-
if option_processors
|
83
|
-
option_processors.each { |processor| processor.call(opts) }
|
84
|
-
end
|
92
|
+
option_processors.each { |processor| processor.call(opts) } if option_processors
|
85
93
|
|
86
94
|
opts
|
87
95
|
end
|
88
96
|
|
89
97
|
def start(opts)
|
90
|
-
exit if opts.help?
|
98
|
+
Kernel.exit if opts.help?
|
91
99
|
|
92
100
|
# invoked via cli
|
93
101
|
Pry.cli = true
|
@@ -95,16 +103,16 @@ class Pry
|
|
95
103
|
# create the actual context
|
96
104
|
if opts[:context]
|
97
105
|
Pry.initial_session_setup
|
98
|
-
context = Pry.binding_for(eval(opts[:context]))
|
106
|
+
context = Pry.binding_for(eval(opts[:context])) # rubocop:disable Security/Eval
|
99
107
|
Pry.final_session_setup
|
100
108
|
else
|
101
109
|
context = Pry.toplevel_binding
|
102
110
|
end
|
103
111
|
|
104
|
-
if Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
|
112
|
+
if !@pass_argv && Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
|
105
113
|
full_name = File.expand_path(Pry::CLI.input_args.first)
|
106
114
|
Pry.load_file_through_repl(full_name)
|
107
|
-
exit
|
115
|
+
Kernel.exit
|
108
116
|
end
|
109
117
|
|
110
118
|
# Start the session (running any code passed with -e, if there is any)
|
@@ -123,20 +131,21 @@ Pry::Slop.new do
|
|
123
131
|
end
|
124
132
|
end.parse(ARGV.dup)
|
125
133
|
|
126
|
-
if Pry.config.should_load_plugins
|
127
|
-
Pry::CLI.add_plugin_options
|
128
|
-
end
|
134
|
+
Pry::CLI.add_plugin_options if Pry.config.should_load_plugins
|
129
135
|
|
130
136
|
# The default Pry command line options (before plugin options are included)
|
131
137
|
Pry::CLI.add_options do
|
132
138
|
banner(
|
133
139
|
"Usage: pry [OPTIONS]\n" \
|
134
140
|
"Start a Pry session.\n" \
|
135
|
-
"See http://pryrepl.org/ for more information.\n"
|
141
|
+
"See http://pryrepl.org/ for more information.\n" \
|
142
|
+
"Copyright (c) 2016 John Mair (banisterfiend)" \
|
136
143
|
)
|
137
144
|
|
138
|
-
on
|
139
|
-
|
145
|
+
on(
|
146
|
+
:e, :exec=, "A line of code to execute in context before the session starts"
|
147
|
+
) do |input|
|
148
|
+
Pry.config.exec_string += "\n" unless Pry.config.exec_string.empty?
|
140
149
|
Pry.config.exec_string += input
|
141
150
|
end
|
142
151
|
|
@@ -174,32 +183,32 @@ Pry::CLI.add_options do
|
|
174
183
|
puts "Installed Plugins:"
|
175
184
|
puts "--"
|
176
185
|
Pry.locate_plugins.each do |plugin|
|
177
|
-
puts
|
186
|
+
puts plugin.name.to_s.ljust(18) << plugin.spec.summary
|
178
187
|
end
|
179
|
-
exit
|
188
|
+
Kernel.exit
|
180
189
|
end
|
181
190
|
|
182
191
|
on "simple-prompt", "Enable simple prompt mode" do
|
183
|
-
Pry.config.prompt = Pry::Prompt[:simple]
|
192
|
+
Pry.config.prompt = Pry::Prompt[:simple]
|
184
193
|
end
|
185
194
|
|
186
195
|
on "noprompt", "No prompt mode" do
|
187
|
-
Pry.config.prompt = Pry::Prompt[:none]
|
196
|
+
Pry.config.prompt = Pry::Prompt[:none]
|
188
197
|
end
|
189
198
|
|
190
199
|
on :r, :require=, "`require` a Ruby script at startup" do |file|
|
191
200
|
Pry.config.requires << file
|
192
201
|
end
|
193
202
|
|
194
|
-
on
|
203
|
+
on(:I=, "Add a path to the $LOAD_PATH", as: Array, delimiter: ":") do |load_path|
|
195
204
|
load_path.map! do |path|
|
196
|
-
|
205
|
+
%r{\A\./} =~ path ? path : File.expand_path(path)
|
197
206
|
end
|
198
207
|
|
199
208
|
$LOAD_PATH.unshift(*load_path)
|
200
209
|
end
|
201
210
|
|
202
|
-
on "gem", "Shorthand for -I./lib -rgemname" do |
|
211
|
+
on "gem", "Shorthand for -I./lib -rgemname" do |_load_path|
|
203
212
|
$LOAD_PATH.unshift("./lib")
|
204
213
|
Dir["./lib/*.rb"].each do |file|
|
205
214
|
Pry.config.requires << file
|
@@ -208,11 +217,11 @@ Pry::CLI.add_options do
|
|
208
217
|
|
209
218
|
on :v, :version, "Display the Pry version" do
|
210
219
|
puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
|
211
|
-
exit
|
220
|
+
Kernel.exit
|
212
221
|
end
|
213
222
|
|
214
|
-
on
|
215
|
-
"Start the session in the specified context. Equivalent to
|
223
|
+
on :c, :context=,
|
224
|
+
"Start the session in the specified context. Equivalent to " \
|
225
|
+
"`context.pry` in a session.",
|
216
226
|
default: "Pry.toplevel_binding"
|
217
|
-
)
|
218
227
|
end
|
data/lib/pry/code.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'method_source'
|
4
4
|
|
5
5
|
class Pry
|
6
6
|
class << self
|
@@ -85,11 +85,10 @@ class Pry
|
|
85
85
|
# @param [Integer?] start_line
|
86
86
|
# @param [Symbol?] code_type
|
87
87
|
def initialize(lines = [], start_line = 1, code_type = :ruby)
|
88
|
-
if lines.is_a? String
|
89
|
-
|
88
|
+
lines = lines.lines if lines.is_a? String
|
89
|
+
@lines = lines.each_with_index.map do |line, lineno|
|
90
|
+
LOC.new(line, lineno + start_line.to_i)
|
90
91
|
end
|
91
|
-
@lines = lines.each_with_index.map { |line, lineno|
|
92
|
-
LOC.new(line, lineno + start_line.to_i) }
|
93
92
|
@code_type = code_type
|
94
93
|
|
95
94
|
@with_marker = @with_indentation = @with_line_numbers = nil
|
@@ -99,14 +98,10 @@ class Pry
|
|
99
98
|
# line, unless specified otherwise.
|
100
99
|
#
|
101
100
|
# @param [String] line
|
102
|
-
# @
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
lineno = @lines.last.lineno + 1
|
107
|
-
end
|
108
|
-
@lines.push(LOC.new(line, lineno))
|
109
|
-
line
|
101
|
+
# @return [void]
|
102
|
+
def push(line)
|
103
|
+
line_number = @lines.any? ? @lines.last.lineno + 1 : 1
|
104
|
+
@lines.push(LOC.new(line, line_number))
|
110
105
|
end
|
111
106
|
alias << push
|
112
107
|
|
@@ -120,6 +115,16 @@ class Pry
|
|
120
115
|
end
|
121
116
|
end
|
122
117
|
|
118
|
+
# Filter the lines using the given block.
|
119
|
+
#
|
120
|
+
# @yield [LOC]
|
121
|
+
# @return [Code]
|
122
|
+
def reject(&block)
|
123
|
+
alter do
|
124
|
+
@lines = @lines.reject(&block)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
123
128
|
# Remove all lines that aren't in the given range, expressed either as a
|
124
129
|
# `Range` object or a first and last line number (inclusive). Negative
|
125
130
|
# indices count from the end of the array of lines.
|
@@ -243,25 +248,20 @@ class Pry
|
|
243
248
|
end
|
244
249
|
end
|
245
250
|
|
246
|
-
# @return [String]
|
247
|
-
def inspect
|
248
|
-
Object.instance_method(:to_s).bind(self).call
|
249
|
-
end
|
250
|
-
|
251
251
|
# @return [Integer] the number of digits in the last line.
|
252
252
|
def max_lineno_width
|
253
|
-
|
253
|
+
!@lines.empty? ? @lines.last.lineno.to_s.length : 0
|
254
254
|
end
|
255
255
|
|
256
256
|
# @return [String] a formatted representation (based on the configuration of
|
257
257
|
# the object).
|
258
258
|
def to_s
|
259
|
-
print_to_output(
|
259
|
+
print_to_output(''.dup, false)
|
260
260
|
end
|
261
261
|
|
262
262
|
# @return [String] a (possibly highlighted) copy of the source code.
|
263
263
|
def highlighted
|
264
|
-
print_to_output(
|
264
|
+
print_to_output(''.dup, true)
|
265
265
|
end
|
266
266
|
|
267
267
|
# Writes a formatted representation (based on the configuration of the
|
@@ -332,14 +332,26 @@ class Pry
|
|
332
332
|
end
|
333
333
|
|
334
334
|
# Forward any missing methods to the output of `#to_s`.
|
335
|
-
def method_missing(
|
336
|
-
|
335
|
+
def method_missing(method_name, *args, &block)
|
336
|
+
if (string = to_s).respond_to?(method_name)
|
337
|
+
string.__send__(method_name, *args, &block)
|
338
|
+
else
|
339
|
+
super
|
340
|
+
end
|
337
341
|
end
|
338
342
|
undef =~
|
339
343
|
|
340
344
|
# Check whether String responds to missing methods.
|
341
|
-
def respond_to_missing?(
|
342
|
-
''.respond_to?(
|
345
|
+
def respond_to_missing?(method_name, include_private = false)
|
346
|
+
''.respond_to?(method_name, include_private) || super
|
347
|
+
end
|
348
|
+
|
349
|
+
if RUBY_VERSION.start_with?('1.9')
|
350
|
+
# @todo This is needed for Ruby 1.9 support where `lines` return an
|
351
|
+
# Enumerator. Newer Rubies return an Array
|
352
|
+
def lines
|
353
|
+
super.to_a
|
354
|
+
end
|
343
355
|
end
|
344
356
|
|
345
357
|
protected
|
data/lib/pry/code/code_file.rb
CHANGED
@@ -1,29 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'method_source'
|
4
|
+
|
1
5
|
class Pry
|
2
6
|
class CodeFile
|
3
|
-
DEFAULT_EXT = '.rb'
|
7
|
+
DEFAULT_EXT = '.rb'.freeze
|
4
8
|
|
5
9
|
# List of all supported languages.
|
6
10
|
# @return [Hash]
|
7
11
|
EXTENSIONS = {
|
8
|
-
%w
|
9
|
-
%w
|
10
|
-
%w
|
11
|
-
%w
|
12
|
-
%w
|
13
|
-
%w
|
14
|
-
%w
|
15
|
-
%w
|
16
|
-
%w
|
17
|
-
%w
|
18
|
-
%w
|
19
|
-
%w
|
20
|
-
%w
|
21
|
-
%w
|
22
|
-
}
|
12
|
+
%w[.py] => :python,
|
13
|
+
%w[.js] => :javascript,
|
14
|
+
%w[.css] => :css,
|
15
|
+
%w[.xml] => :xml,
|
16
|
+
%w[.php] => :php,
|
17
|
+
%w[.html] => :html,
|
18
|
+
%w[.diff] => :diff,
|
19
|
+
%w[.java] => :java,
|
20
|
+
%w[.json] => :json,
|
21
|
+
%w[.c .h] => :c,
|
22
|
+
%w[.rhtml] => :rhtml,
|
23
|
+
%w[.yaml .yml] => :yaml,
|
24
|
+
%w[.cpp .hpp .cc .h .cxx] => :cpp,
|
25
|
+
%w[.rb .ru .irbrc .gemspec .pryrc .rake] => :ruby
|
26
|
+
}.freeze
|
23
27
|
|
24
28
|
FILES = {
|
25
|
-
%w
|
26
|
-
}
|
29
|
+
%w[Gemfile Rakefile Guardfile Capfile] => :ruby
|
30
|
+
}.freeze
|
27
31
|
|
28
32
|
# Store the current working directory. This allows show-source etc. to work if
|
29
33
|
# your process has changed directory since boot. [Issue #675]
|
@@ -58,16 +62,16 @@ class Pry
|
|
58
62
|
# readable for some reason.
|
59
63
|
# @return [String] absolute path for the given `filename`.
|
60
64
|
def abs_path
|
61
|
-
code_path.detect { |path| readable?(path) }
|
62
|
-
raise
|
63
|
-
"Cannot open #{
|
65
|
+
code_path.detect { |path| readable?(path) } ||
|
66
|
+
raise(MethodSource::SourceNotFoundError,
|
67
|
+
"Cannot open #{@filename.inspect} for reading.")
|
64
68
|
end
|
65
69
|
|
66
70
|
# @param [String] path
|
67
71
|
# @return [Boolean] if the path, with or without the default ext,
|
68
72
|
# is a readable file then `true`, otherwise `false`.
|
69
73
|
def readable?(path)
|
70
|
-
File.readable?(path) && !File.directory?(path)
|
74
|
+
File.readable?(path) && !File.directory?(path) ||
|
71
75
|
File.readable?(path << DEFAULT_EXT)
|
72
76
|
end
|
73
77
|
|
@@ -80,8 +84,8 @@ class Pry
|
|
80
84
|
# @param [String] filename
|
81
85
|
# @param [Symbol] default (:unknown) the file type to assume if none could be
|
82
86
|
# detected.
|
83
|
-
# @return [Symbol, nil] The
|
84
|
-
# `nil` if `:unknown`.
|
87
|
+
# @return [Symbol, nil] The SyntaxHighlighter type of a file from its
|
88
|
+
# extension, or `nil` if `:unknown`.
|
85
89
|
def type_from_filename(filename, default = :unknown)
|
86
90
|
_, @code_type = EXTENSIONS.find do |k, _|
|
87
91
|
k.any? { |ext| ext == File.extname(filename) }
|
data/lib/pry/code/code_range.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
class Code
|
3
5
|
# Represents a range of lines in a code listing.
|
@@ -20,9 +22,9 @@ class Pry
|
|
20
22
|
|
21
23
|
private
|
22
24
|
|
23
|
-
|
25
|
+
attr_reader :start_line
|
24
26
|
|
25
|
-
|
27
|
+
attr_reader :end_line
|
26
28
|
|
27
29
|
# If `end_line` is equal to `nil`, then calculate it from the first
|
28
30
|
# parameter, `start_line`. Otherwise, leave it as it is.
|
data/lib/pry/code/loc.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
class Code
|
3
|
-
# Represents a line of code (which may, in fact, contain multiple lines if
|
4
|
-
# entirety was eval'd as a single unit following the `edit` command).
|
5
|
+
# Represents a line of code (which may, in fact, contain multiple lines if
|
6
|
+
# the entirety was eval'd as a single unit following the `edit` command).
|
5
7
|
#
|
6
8
|
# A line of code is a tuple, which consists of a line and a line number. A
|
7
9
|
# `LOC` object's state (namely, the line parameter) can be changed via
|
@@ -52,7 +54,7 @@ class Pry
|
|
52
54
|
# @param [Symbol] code_type
|
53
55
|
# @return [void]
|
54
56
|
def colorize(code_type)
|
55
|
-
tuple[0] =
|
57
|
+
tuple[0] = SyntaxHighlighter.highlight(line, code_type)
|
56
58
|
end
|
57
59
|
|
58
60
|
# Prepends the line number `lineno` to the `line`.
|
@@ -61,9 +63,14 @@ class Pry
|
|
61
63
|
# @return [void]
|
62
64
|
def add_line_number(max_width = 0, color = false)
|
63
65
|
padded = lineno.to_s.rjust(max_width)
|
64
|
-
colorized_lineno =
|
66
|
+
colorized_lineno =
|
67
|
+
if color
|
68
|
+
Pry::Helpers::BaseHelpers.colorize_code(padded)
|
69
|
+
else
|
70
|
+
padded
|
71
|
+
end
|
65
72
|
properly_padded_line = handle_multiline_entries_from_edit_command(line, max_width)
|
66
|
-
tuple[0] = "#{
|
73
|
+
tuple[0] = "#{colorized_lineno}: #{properly_padded_line}"
|
67
74
|
end
|
68
75
|
|
69
76
|
# Prepends a marker "=>" or an empty marker to the +line+.
|
@@ -74,9 +81,9 @@ class Pry
|
|
74
81
|
def add_marker(marker_lineno)
|
75
82
|
tuple[0] =
|
76
83
|
if lineno == marker_lineno
|
77
|
-
" => #{
|
84
|
+
" => #{line}"
|
78
85
|
else
|
79
|
-
" #{
|
86
|
+
" #{line}"
|
80
87
|
end
|
81
88
|
end
|
82
89
|
|
@@ -85,7 +92,7 @@ class Pry
|
|
85
92
|
# @param [Integer] distance
|
86
93
|
# @return [void]
|
87
94
|
def indent(distance)
|
88
|
-
tuple[0] = "#{
|
95
|
+
tuple[0] = "#{' ' * distance}#{line}"
|
89
96
|
end
|
90
97
|
|
91
98
|
def handle_multiline_entries_from_edit_command(line, max_width)
|
data/lib/pry/code_object.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
# This class is responsible for taking a string (identifying a
|
3
5
|
# command/class/method/etc) and returning the relevant type of object.
|
@@ -42,29 +44,30 @@ class Pry
|
|
42
44
|
# @note If a module defined by C was extended with a lot of methods written
|
43
45
|
# in Ruby, this method would fail.
|
44
46
|
def c_module?
|
45
|
-
|
47
|
+
return unless is_a?(WrappedModule)
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
method_locations = wrapped.methods(false).map do |m|
|
50
|
+
wrapped.method(m).source_location
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
method_locations.concat(
|
54
|
+
wrapped.instance_methods(false).map do |m|
|
55
|
+
wrapped.instance_method(m).source_location
|
56
|
+
end
|
57
|
+
)
|
54
58
|
|
55
|
-
|
56
|
-
|
59
|
+
c_methods = method_locations.grep(nil).count
|
60
|
+
ruby_methods = method_locations.count - c_methods
|
57
61
|
|
58
|
-
|
59
|
-
end
|
62
|
+
c_methods > ruby_methods
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
63
66
|
include Pry::Helpers::CommandHelpers
|
64
67
|
|
65
68
|
class << self
|
66
|
-
def lookup(str,
|
67
|
-
co = new(str,
|
69
|
+
def lookup(str, pry_instance, options = {})
|
70
|
+
co = new(str, pry_instance, options)
|
68
71
|
|
69
72
|
co.default_lookup || co.method_or_class_lookup ||
|
70
73
|
co.command_lookup || co.empty_lookup
|
@@ -73,24 +76,25 @@ class Pry
|
|
73
76
|
|
74
77
|
attr_accessor :str
|
75
78
|
attr_accessor :target
|
76
|
-
attr_accessor :
|
79
|
+
attr_accessor :pry_instance
|
77
80
|
attr_accessor :super_level
|
78
81
|
|
79
|
-
def initialize(str,
|
82
|
+
def initialize(str, pry_instance, options = {})
|
80
83
|
options = {
|
81
|
-
super: 0
|
84
|
+
super: 0
|
82
85
|
}.merge!(options)
|
83
86
|
|
84
87
|
@str = str
|
85
|
-
@
|
86
|
-
@target =
|
88
|
+
@pry_instance = pry_instance
|
89
|
+
@target = pry_instance.current_context
|
87
90
|
@super_level = options[:super]
|
88
91
|
end
|
89
92
|
|
93
|
+
# TODO: just make it so find_command_by_match_or_listing doesn't raise?
|
90
94
|
def command_lookup
|
91
|
-
|
92
|
-
|
93
|
-
|
95
|
+
pry_instance.commands.find_command_by_match_or_listing(str)
|
96
|
+
rescue StandardError
|
97
|
+
nil
|
94
98
|
end
|
95
99
|
|
96
100
|
# when no paramter is given (i.e CodeObject.lookup(nil)), then we
|
@@ -112,8 +116,8 @@ class Pry
|
|
112
116
|
|
113
117
|
# lookup variables and constants and `self` that are not modules
|
114
118
|
def default_lookup
|
115
|
-
|
116
|
-
#
|
119
|
+
# we skip instance methods as we want those to fall through to
|
120
|
+
# method_or_class_lookup()
|
117
121
|
if safe_to_evaluate?(str) && !looks_like_an_instance_method?(str)
|
118
122
|
obj = target.eval(str)
|
119
123
|
|
@@ -123,22 +127,22 @@ class Pry
|
|
123
127
|
Pry::Method(obj)
|
124
128
|
elsif !obj.is_a?(Module)
|
125
129
|
Pry::WrappedModule(obj.class)
|
126
|
-
else
|
127
|
-
nil
|
128
130
|
end
|
129
131
|
end
|
130
|
-
|
131
132
|
rescue Pry::RescuableException
|
132
133
|
nil
|
133
134
|
end
|
134
135
|
|
135
136
|
def method_or_class_lookup
|
136
|
-
obj =
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
137
|
+
obj =
|
138
|
+
case str
|
139
|
+
when /\S+\(\)\z/
|
140
|
+
Pry::Method.from_str(str.sub(/\(\)\z/, ''), target) ||
|
141
|
+
Pry::WrappedModule.from_str(str, target)
|
142
|
+
else
|
143
|
+
Pry::WrappedModule.from_str(str, target) ||
|
144
|
+
Pry::Method.from_str(str, target)
|
145
|
+
end
|
142
146
|
|
143
147
|
lookup_super(obj, super_level)
|
144
148
|
end
|
@@ -182,14 +186,12 @@ class Pry
|
|
182
186
|
# @param [Object] obj
|
183
187
|
# @param [Fixnum] super_level How far up the super chain to ascend.
|
184
188
|
def lookup_super(obj, super_level)
|
185
|
-
return
|
189
|
+
return unless obj
|
186
190
|
|
187
191
|
sup = obj.super(super_level)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
sup
|
192
|
-
end
|
192
|
+
raise Pry::CommandError, "No superclass found for #{obj.wrapped}" unless sup
|
193
|
+
|
194
|
+
sup
|
193
195
|
end
|
194
196
|
end
|
195
197
|
end
|