pry 0.12.2-java → 0.13.0-java
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 +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
@@ -1,215 +1,233 @@
|
|
1
|
-
|
2
|
-
class Command::ShowInfo < Pry::ClassCommand
|
3
|
-
extend Pry::Helpers::BaseHelpers
|
4
|
-
|
5
|
-
command_options shellwords: false, interpolate: false
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
8
|
-
|
3
|
+
class Pry
|
4
|
+
class Command
|
5
|
+
class ShowInfo < Pry::ClassCommand
|
6
|
+
extend Pry::Helpers::BaseHelpers
|
9
7
|
|
10
|
-
|
11
|
-
end
|
8
|
+
command_options shellwords: false, interpolate: false
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
opt.on :l, "line-numbers", "Show line numbers"
|
16
|
-
opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)"
|
17
|
-
opt.on :a, :all, "Show all definitions and monkeypatches of the module/class"
|
18
|
-
end
|
10
|
+
def initialize(*)
|
11
|
+
super
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
raise CommandError, no_definition_message if !code_object
|
13
|
+
@used_super = nil
|
14
|
+
end
|
23
15
|
|
24
|
-
|
16
|
+
def options(opt)
|
17
|
+
opt.on :s, :super, "Select the 'super' method. Can be repeated to " \
|
18
|
+
"traverse the ancestors", as: :count
|
19
|
+
opt.on :l, "line-numbers", "Show line numbers"
|
20
|
+
opt.on :b, "base-one", "Show line numbers but start numbering at 1 " \
|
21
|
+
"(useful for `amend-line` and `play` commands)"
|
22
|
+
opt.on :a, :all, "Show all definitions and monkeypatches of the " \
|
23
|
+
"module/class"
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
def process
|
27
|
+
code_object = Pry::CodeObject.lookup(obj_name, pry_instance, super: opts[:super])
|
28
|
+
raise CommandError, no_definition_message unless code_object
|
29
|
+
|
30
|
+
@original_code_object = code_object
|
31
|
+
|
32
|
+
if !obj_name && code_object.c_module? && !opts[:all]
|
33
|
+
result = "You're inside an object, whose class is defined by means of " \
|
34
|
+
"the C Ruby API.\nPry cannot display the information for this " \
|
35
|
+
"class."
|
36
|
+
if code_object.candidates.any?
|
37
|
+
result += "\nHowever, you can view monkey-patches applied to this " \
|
38
|
+
"class.\n.Just execute the same command with the '--all' " \
|
39
|
+
"switch."
|
40
|
+
end
|
41
|
+
elsif show_all_modules?(code_object)
|
42
|
+
# show all monkey patches for a module
|
43
|
+
|
44
|
+
result = content_and_headers_for_all_module_candidates(code_object)
|
45
|
+
else
|
46
|
+
# show a specific code object
|
47
|
+
co = code_object_with_accessible_source(code_object)
|
48
|
+
result = content_and_header_for_code_object(co)
|
33
49
|
end
|
34
|
-
elsif show_all_modules?(code_object)
|
35
|
-
# show all monkey patches for a module
|
36
50
|
|
37
|
-
|
38
|
-
|
39
|
-
# show a specific code object
|
40
|
-
co = code_object_with_accessible_source(code_object)
|
41
|
-
result = content_and_header_for_code_object(co)
|
51
|
+
set_file_and_dir_locals(code_object.source_file)
|
52
|
+
pry_instance.pager.page result
|
42
53
|
end
|
43
54
|
|
44
|
-
|
45
|
-
|
46
|
-
|
55
|
+
# This method checks whether the `code_object` is a WrappedModule, if it
|
56
|
+
# is, then it returns the first candidate (monkeypatch) with accessible
|
57
|
+
# source (or docs). If `code_object` is not a WrappedModule (i.e a method
|
58
|
+
# or a command) then the `code_object` itself is just returned.
|
59
|
+
#
|
60
|
+
# @return [Pry::WrappedModule, Pry::Method, Pry::Command]
|
61
|
+
def code_object_with_accessible_source(code_object)
|
62
|
+
return code_object unless code_object.is_a?(WrappedModule)
|
47
63
|
|
48
|
-
# This method checks whether the `code_object` is a WrappedModule,
|
49
|
-
# if it is, then it returns the first candidate (monkeypatch) with
|
50
|
-
# accessible source (or docs). If `code_object` is not a WrappedModule (i.e a
|
51
|
-
# method or a command) then the `code_object` itself is just
|
52
|
-
# returned.
|
53
|
-
#
|
54
|
-
# @return [Pry::WrappedModule, Pry::Method, Pry::Command]
|
55
|
-
def code_object_with_accessible_source(code_object)
|
56
|
-
if code_object.is_a?(WrappedModule)
|
57
64
|
candidate = code_object.candidates.find(&:source)
|
58
|
-
if candidate
|
59
|
-
return candidate
|
60
|
-
else
|
61
|
-
raise CommandError, no_definition_message if !valid_superclass?(code_object)
|
65
|
+
return candidate if candidate
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
code_object
|
67
|
+
raise CommandError, no_definition_message unless valid_superclass?(code_object)
|
68
|
+
|
69
|
+
@used_super = true
|
70
|
+
code_object_with_accessible_source(code_object.super)
|
68
71
|
end
|
69
|
-
end
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
def valid_superclass?(code_object)
|
74
|
+
code_object.super && code_object.super.wrapped != Object
|
75
|
+
end
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
77
|
+
def content_and_header_for_code_object(code_object)
|
78
|
+
header(code_object) + content_for(code_object)
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
81
|
+
def content_and_headers_for_all_module_candidates(mod)
|
82
|
+
result = "Found #{mod.number_of_candidates} candidates for " \
|
83
|
+
"`#{mod.name}` definition:\n"
|
84
|
+
mod.number_of_candidates.times do |v|
|
85
|
+
candidate = mod.candidate(v)
|
86
|
+
begin
|
87
|
+
result += "\nCandidate #{v + 1}/#{mod.number_of_candidates}: " \
|
88
|
+
"#{candidate.source_file}:#{candidate.source_line}\n"
|
89
|
+
content = content_for(candidate)
|
90
|
+
|
91
|
+
result += "Number of lines: #{content.lines.count}\n\n" + content
|
92
|
+
rescue Pry::RescuableException
|
93
|
+
result += "\nNo content found.\n"
|
94
|
+
next
|
95
|
+
end
|
91
96
|
end
|
97
|
+
result
|
92
98
|
end
|
93
|
-
result
|
94
|
-
end
|
95
99
|
|
96
|
-
|
97
|
-
|
98
|
-
|
100
|
+
def no_definition_message
|
101
|
+
"Couldn't locate a definition for #{obj_name}"
|
102
|
+
end
|
99
103
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
104
|
+
# Generate a header (meta-data information) for all the code
|
105
|
+
# object types: methods, modules, commands, procs...
|
106
|
+
def header(code_object)
|
107
|
+
file_name, line_num = file_and_line_for(code_object)
|
108
|
+
content = content_for(code_object)
|
109
|
+
|
110
|
+
h = "\n#{bold('From:')} #{file_name}"
|
111
|
+
h += code_object_header(code_object, line_num)
|
112
|
+
h += "\n#{bold('Number of lines:')} " + "#{content.lines.count}\n\n"
|
113
|
+
if @used_super
|
114
|
+
h += bold('** Warning:')
|
115
|
+
h += " Cannot find code for #{@original_code_object.nonblank_name}. " \
|
116
|
+
"Showing superclass #{code_object.nonblank_name} instead. **\n\n"
|
117
|
+
end
|
105
118
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
119
|
+
if content.lines.none?
|
120
|
+
h += bold('** Warning:')
|
121
|
+
h += " Cannot find code for '#{code_object.name}' (source_location is nil)"
|
122
|
+
end
|
110
123
|
|
111
|
-
|
112
|
-
h << bold('** Warning:') << " Cannot find code for '#{code_object.name}' (source_location is nil)"
|
124
|
+
h
|
113
125
|
end
|
114
126
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
def code_object_header(code_object, line_num)
|
119
|
-
if code_object.real_method_object?
|
120
|
-
method_header(code_object, line_num)
|
127
|
+
def code_object_header(code_object, line_num)
|
128
|
+
if code_object.real_method_object?
|
129
|
+
method_header(code_object, line_num)
|
121
130
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
131
|
+
# It sucks we have to test for both Pry::WrappedModule and
|
132
|
+
# WrappedModule::Candidate, probably indicates a deep refactor needs
|
133
|
+
# to happen in those classes.
|
134
|
+
elsif code_object.is_a?(Pry::WrappedModule) ||
|
135
|
+
code_object.is_a?(Pry::WrappedModule::Candidate)
|
136
|
+
module_header(code_object, line_num)
|
137
|
+
else
|
138
|
+
""
|
139
|
+
end
|
128
140
|
end
|
129
|
-
end
|
130
141
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
142
|
+
def method_header(code_object, line_num)
|
143
|
+
h = ""
|
144
|
+
h += (code_object.c_method? ? ' (C Method):' : ":#{line_num}:")
|
145
|
+
h += method_sections(code_object)[:owner]
|
146
|
+
h += method_sections(code_object)[:visibility]
|
147
|
+
h += method_sections(code_object)[:signature]
|
148
|
+
h
|
149
|
+
end
|
139
150
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
151
|
+
def module_header(code_object, line_num)
|
152
|
+
h = ""
|
153
|
+
h += ":#{line_num}\n"
|
154
|
+
h += bold(code_object.module? ? "Module" : "Class")
|
155
|
+
h += " #{bold('name:')} #{code_object.nonblank_name}"
|
145
156
|
|
146
|
-
|
147
|
-
|
148
|
-
|
157
|
+
if code_object.number_of_candidates > 1
|
158
|
+
h += bold("\nNumber of monkeypatches: ")
|
159
|
+
h += code_object.number_of_candidates.to_s
|
160
|
+
h += ". Use the `-a` option to display all available monkeypatches"
|
161
|
+
end
|
162
|
+
h
|
149
163
|
end
|
150
|
-
h
|
151
|
-
end
|
152
164
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
165
|
+
def method_sections(code_object)
|
166
|
+
{
|
167
|
+
owner: "\n#{bold('Owner:')} #{code_object.owner || 'N/A'}\n",
|
168
|
+
visibility: "#{bold('Visibility:')} #{code_object.visibility}",
|
169
|
+
signature: "\n#{bold('Signature:')} #{code_object.signature}"
|
170
|
+
}.merge(header_options) { |_key, old, new| (new && old).to_s }
|
171
|
+
end
|
160
172
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
173
|
+
def header_options
|
174
|
+
{
|
175
|
+
owner: true,
|
176
|
+
visibility: true,
|
177
|
+
signature: nil
|
178
|
+
}
|
179
|
+
end
|
168
180
|
|
169
|
-
|
170
|
-
|
171
|
-
|
181
|
+
def show_all_modules?(code_object)
|
182
|
+
code_object.is_a?(Pry::WrappedModule) && opts.present?(:all)
|
183
|
+
end
|
172
184
|
|
173
|
-
|
174
|
-
|
175
|
-
|
185
|
+
def obj_name
|
186
|
+
@obj_name ||= args.empty? ? nil : args.join(' ')
|
187
|
+
end
|
176
188
|
|
177
|
-
|
178
|
-
|
179
|
-
|
189
|
+
def use_line_numbers?
|
190
|
+
opts.present?(:b) || opts.present?(:l)
|
191
|
+
end
|
180
192
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
193
|
+
def start_line_for(code_object)
|
194
|
+
if opts.present?(:'base-one')
|
195
|
+
1
|
196
|
+
else
|
197
|
+
code_object.source_line || 1
|
198
|
+
end
|
186
199
|
end
|
187
|
-
end
|
188
200
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
201
|
+
# takes into account possible yard docs, and returns yard_file / yard_line
|
202
|
+
# Also adjusts for start line of comments (using start_line_for), which it
|
203
|
+
# has to infer by subtracting number of lines of comment from start line
|
204
|
+
# of code_object
|
205
|
+
def file_and_line_for(code_object)
|
206
|
+
if code_object.module_with_yard_docs?
|
207
|
+
[code_object.yard_file, code_object.yard_line]
|
208
|
+
else
|
209
|
+
[code_object.source_file, start_line_for(code_object)]
|
210
|
+
end
|
197
211
|
end
|
198
|
-
end
|
199
212
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
+
def complete(input)
|
214
|
+
if input =~ /([^ ]*)#([a-z0-9_]*)\z/
|
215
|
+
prefix = Regexp.last_match(1)
|
216
|
+
search = Regexp.last_match(2)
|
217
|
+
methods =
|
218
|
+
begin
|
219
|
+
# rubocop:disable Security/Eval
|
220
|
+
Pry::Method.all_from_class(binding.eval(prefix))
|
221
|
+
# rubocop:enable Security/Eval
|
222
|
+
rescue RescuableException
|
223
|
+
return super
|
224
|
+
end
|
225
|
+
methods.map do |method|
|
226
|
+
[prefix, method.name].join('#') if method.name.start_with?(search)
|
227
|
+
end.compact
|
228
|
+
else
|
229
|
+
super
|
230
|
+
end
|
213
231
|
end
|
214
232
|
end
|
215
233
|
end
|
@@ -1,17 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class ShowInput < Pry::ClassCommand
|
6
|
+
match 'show-input'
|
7
|
+
group 'Editing'
|
8
|
+
description 'Show the contents of the input buffer for the current ' \
|
9
|
+
'multi-line expression.'
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
11
|
+
banner <<-'BANNER'
|
12
|
+
Show the contents of the input buffer for the current multi-line expression.
|
13
|
+
BANNER
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
def process
|
16
|
+
output.puts Code.new(eval_string).with_line_numbers
|
17
|
+
end
|
13
18
|
end
|
14
|
-
end
|
15
19
|
|
16
|
-
|
20
|
+
Pry::Commands.add_command(Pry::Command::ShowInput)
|
21
|
+
end
|
17
22
|
end
|
@@ -1,53 +1,117 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Pry
|
4
|
-
class Command
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
show-source Pry#rep # source for Pry#rep method
|
19
|
-
show-source Pry # for Pry class
|
20
|
-
show-source Pry -a # for all Pry class definitions (all monkey patches)
|
21
|
-
show-source Pry.foo -e # for class of the return value of expression `Pry.foo`
|
22
|
-
show-source Pry --super # for superclass of Pry (Object class)
|
23
|
-
|
24
|
-
https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
|
25
|
-
BANNER
|
26
|
-
|
27
|
-
def options(opt)
|
28
|
-
opt.on :e, :eval, "evaluate the command's argument as a ruby expression and show the class its return value"
|
29
|
-
super(opt)
|
30
|
-
end
|
4
|
+
class Command
|
5
|
+
class ShowSource < Command::ShowInfo
|
6
|
+
include Pry::Helpers::DocumentationHelpers
|
7
|
+
|
8
|
+
match 'show-source'
|
9
|
+
group 'Introspection'
|
10
|
+
description 'Show the source for a method or class.'
|
11
|
+
|
12
|
+
banner <<-'BANNER'
|
13
|
+
Usage: show-source [OPTIONS] [METH|CLASS]
|
14
|
+
Aliases: $, show-method
|
15
|
+
|
16
|
+
Show the source for a method or class. Tries instance methods first and then
|
17
|
+
methods by default.
|
31
18
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
show-source hi_method
|
20
|
+
show-source hi_method
|
21
|
+
show-source Pry#rep # source for Pry#rep method
|
22
|
+
show-source Pry # for Pry class
|
23
|
+
show-source Pry -a # for all Pry class definitions (all monkey patches)
|
24
|
+
show-source Pry.foo -e # for class of the return value of expression `Pry.foo`
|
25
|
+
show-source Pry --super # for superclass of Pry (Object class)
|
26
|
+
show-source Pry -d # include documentation
|
27
|
+
|
28
|
+
https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
|
29
|
+
BANNER
|
30
|
+
|
31
|
+
def options(opt)
|
32
|
+
opt.on :e, :eval, "evaluate the command's argument as a ruby " \
|
33
|
+
"expression and show the class its return value"
|
34
|
+
opt.on :d, :doc, 'include documentation in the output'
|
35
|
+
super(opt)
|
36
|
+
end
|
37
|
+
|
38
|
+
def process
|
39
|
+
if opts.present?(:e)
|
40
|
+
obj = target.eval(args.first)
|
41
|
+
self.args = Array.new(1) { obj.is_a?(Module) ? obj.name : obj.class.name }
|
42
|
+
end
|
43
|
+
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
# The source for code_object prepared for display.
|
48
|
+
def content_for(code_object)
|
49
|
+
content = ''
|
50
|
+
if opts.present?(:d)
|
51
|
+
code = Code.new(
|
52
|
+
render_doc_markup_for(code_object), start_line_for(code_object), :text
|
53
|
+
)
|
54
|
+
content += code.with_line_numbers(use_line_numbers?).to_s
|
55
|
+
content += "\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
code = Code.new(
|
59
|
+
code_object.source || [], start_line_for(code_object)
|
60
|
+
)
|
61
|
+
content += code.with_line_numbers(use_line_numbers?).highlighted
|
62
|
+
content
|
36
63
|
end
|
37
|
-
super
|
38
|
-
end
|
39
64
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
65
|
+
# process the markup (if necessary) and apply colors
|
66
|
+
def render_doc_markup_for(code_object)
|
67
|
+
docs = docs_for(code_object)
|
68
|
+
|
69
|
+
if code_object.command?
|
70
|
+
# command '--help' shouldn't use markup highlighting
|
71
|
+
docs
|
72
|
+
else
|
73
|
+
if docs.empty?
|
74
|
+
raise CommandError, "No docs found for: #{obj_name || 'current context'}"
|
75
|
+
end
|
76
|
+
|
77
|
+
process_comment_markup(docs)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Return docs for the code_object, adjusting for whether the code_object
|
82
|
+
# has yard docs available, in which case it returns those.
|
83
|
+
# (note we only have to check yard docs for modules since they can
|
84
|
+
# have multiple docs, but methods can only be doc'd once so we
|
85
|
+
# dont need to check them)
|
86
|
+
def docs_for(code_object)
|
87
|
+
if code_object.module_with_yard_docs?
|
88
|
+
# yard docs
|
89
|
+
code_object.yard_doc
|
90
|
+
else
|
91
|
+
# normal docs (i.e comments above method/module/command)
|
92
|
+
code_object.doc
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Which sections to include in the 'header', can toggle: :owner,
|
97
|
+
# :signature and visibility.
|
98
|
+
def header_options
|
99
|
+
super.merge signature: true
|
100
|
+
end
|
101
|
+
|
102
|
+
# figure out start line of docs by back-calculating based on
|
103
|
+
# number of lines in the comment and the start line of the code_object
|
104
|
+
# @return [Fixnum] start line of docs
|
105
|
+
def start_line_for(code_object)
|
106
|
+
return 1 if code_object.command? || opts.present?(:'base-one')
|
107
|
+
return 1 unless code_object.source_line
|
108
|
+
|
109
|
+
code_object.source_line - code_object.doc.lines.count
|
110
|
+
end
|
47
111
|
end
|
48
|
-
end
|
49
112
|
|
50
|
-
|
51
|
-
|
52
|
-
|
113
|
+
Pry::Commands.add_command(Pry::Command::ShowSource)
|
114
|
+
Pry::Commands.alias_command 'show-method', 'show-source'
|
115
|
+
Pry::Commands.alias_command '$', 'show-source'
|
116
|
+
end
|
53
117
|
end
|