pry 0.9.12.2 → 0.14.2

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.
Files changed (237) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1141 -0
  3. data/LICENSE +2 -2
  4. data/README.md +466 -0
  5. data/bin/pry +4 -7
  6. data/lib/pry/basic_object.rb +10 -0
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +97 -92
  10. data/lib/pry/code/code_file.rb +114 -0
  11. data/lib/pry/code/code_range.rb +7 -4
  12. data/lib/pry/code/loc.rb +27 -14
  13. data/lib/pry/code.rb +62 -90
  14. data/lib/pry/code_object.rb +83 -39
  15. data/lib/pry/color_printer.rb +66 -0
  16. data/lib/pry/command.rb +202 -371
  17. data/lib/pry/command_set.rb +151 -133
  18. data/lib/pry/command_state.rb +31 -0
  19. data/lib/pry/commands/amend_line.rb +86 -82
  20. data/lib/pry/commands/bang.rb +18 -14
  21. data/lib/pry/commands/bang_pry.rb +15 -11
  22. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  23. data/lib/pry/commands/cat/exception_formatter.rb +85 -73
  24. data/lib/pry/commands/cat/file_formatter.rb +56 -63
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +64 -47
  27. data/lib/pry/commands/cd.rb +42 -26
  28. data/lib/pry/commands/change_inspector.rb +34 -0
  29. data/lib/pry/commands/change_prompt.rb +51 -0
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -131
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +23 -34
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +33 -24
  36. data/lib/pry/commands/edit.rb +183 -167
  37. data/lib/pry/commands/exit.rb +40 -35
  38. data/lib/pry/commands/exit_all.rb +24 -20
  39. data/lib/pry/commands/exit_program.rb +20 -17
  40. data/lib/pry/commands/find_method.rb +167 -167
  41. data/lib/pry/commands/fix_indent.rb +16 -12
  42. data/lib/pry/commands/help.rb +140 -133
  43. data/lib/pry/commands/hist.rb +153 -132
  44. data/lib/pry/commands/import_set.rb +20 -15
  45. data/lib/pry/commands/jump_to.rb +25 -21
  46. data/lib/pry/commands/list_inspectors.rb +42 -0
  47. data/lib/pry/commands/ls/constants.rb +75 -0
  48. data/lib/pry/commands/ls/formatter.rb +55 -0
  49. data/lib/pry/commands/ls/globals.rb +50 -0
  50. data/lib/pry/commands/ls/grep.rb +23 -0
  51. data/lib/pry/commands/ls/instance_vars.rb +40 -0
  52. data/lib/pry/commands/ls/interrogatable.rb +24 -0
  53. data/lib/pry/commands/ls/jruby_hacks.rb +55 -0
  54. data/lib/pry/commands/ls/local_names.rb +37 -0
  55. data/lib/pry/commands/ls/local_vars.rb +47 -0
  56. data/lib/pry/commands/ls/ls_entity.rb +65 -0
  57. data/lib/pry/commands/ls/methods.rb +55 -0
  58. data/lib/pry/commands/ls/methods_helper.rb +50 -0
  59. data/lib/pry/commands/ls/self_methods.rb +34 -0
  60. data/lib/pry/commands/ls.rb +100 -303
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +93 -49
  63. data/lib/pry/commands/pry_backtrace.rb +22 -18
  64. data/lib/pry/commands/pry_version.rb +15 -11
  65. data/lib/pry/commands/raise_up.rb +33 -27
  66. data/lib/pry/commands/reload_code.rb +57 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +57 -38
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +66 -34
  71. data/lib/pry/commands/shell_mode.rb +22 -20
  72. data/lib/pry/commands/show_doc.rb +80 -65
  73. data/lib/pry/commands/show_info.rb +193 -159
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +113 -33
  76. data/lib/pry/commands/stat.rb +35 -31
  77. data/lib/pry/commands/switch_to.rb +21 -15
  78. data/lib/pry/commands/toggle_color.rb +21 -13
  79. data/lib/pry/commands/watch_expression/expression.rb +43 -0
  80. data/lib/pry/commands/watch_expression.rb +110 -0
  81. data/lib/pry/commands/whereami.rb +157 -134
  82. data/lib/pry/commands/wtf.rb +78 -40
  83. data/lib/pry/config/attributable.rb +22 -0
  84. data/lib/pry/config/lazy_value.rb +29 -0
  85. data/lib/pry/config/memoized_value.rb +34 -0
  86. data/lib/pry/config/value.rb +24 -0
  87. data/lib/pry/config.rb +290 -220
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +50 -27
  90. data/lib/pry/editor.rb +130 -102
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +73 -0
  94. data/lib/pry/forwardable.rb +27 -0
  95. data/lib/pry/helpers/base_helpers.rb +22 -151
  96. data/lib/pry/helpers/command_helpers.rb +55 -63
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -13
  98. data/lib/pry/helpers/options_helpers.rb +15 -8
  99. data/lib/pry/helpers/platform.rb +55 -0
  100. data/lib/pry/helpers/table.rb +44 -32
  101. data/lib/pry/helpers/text.rb +96 -86
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +101 -70
  104. data/lib/pry/hooks.rb +67 -137
  105. data/lib/pry/indent.rb +79 -73
  106. data/lib/pry/input_completer.rb +283 -0
  107. data/lib/pry/input_lock.rb +129 -0
  108. data/lib/pry/inspector.rb +39 -0
  109. data/lib/pry/last_exception.rb +61 -0
  110. data/lib/pry/method/disowned.rb +19 -5
  111. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +51 -42
  112. data/lib/pry/method/weird_method_locator.rb +80 -44
  113. data/lib/pry/method.rb +225 -176
  114. data/lib/pry/object_path.rb +91 -0
  115. data/lib/pry/output.rb +136 -0
  116. data/lib/pry/pager.rb +227 -68
  117. data/lib/pry/prompt.rb +214 -0
  118. data/lib/pry/pry_class.rb +216 -289
  119. data/lib/pry/pry_instance.rb +438 -500
  120. data/lib/pry/repl.rb +256 -0
  121. data/lib/pry/repl_file_loader.rb +34 -35
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/LICENSE +20 -0
  124. data/lib/pry/slop/commands.rb +190 -0
  125. data/lib/pry/slop/option.rb +210 -0
  126. data/lib/pry/slop.rb +672 -0
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable/evalable.rb +24 -0
  130. data/lib/pry/testable/mockable.rb +22 -0
  131. data/lib/pry/testable/pry_tester.rb +88 -0
  132. data/lib/pry/testable/utility.rb +34 -0
  133. data/lib/pry/testable/variables.rb +52 -0
  134. data/lib/pry/testable.rb +68 -0
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +20 -0
  137. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +36 -43
  138. data/lib/pry/wrapped_module.rb +102 -103
  139. data/lib/pry.rb +135 -261
  140. metadata +94 -283
  141. data/.document +0 -2
  142. data/.gitignore +0 -16
  143. data/.travis.yml +0 -21
  144. data/.yardopts +0 -1
  145. data/CHANGELOG +0 -534
  146. data/CONTRIBUTORS +0 -55
  147. data/Gemfile +0 -9
  148. data/Guardfile +0 -62
  149. data/README.markdown +0 -400
  150. data/Rakefile +0 -140
  151. data/TODO +0 -117
  152. data/lib/pry/commands/disabled_commands.rb +0 -2
  153. data/lib/pry/commands/gem_cd.rb +0 -26
  154. data/lib/pry/commands/gem_install.rb +0 -29
  155. data/lib/pry/commands/gem_list.rb +0 -33
  156. data/lib/pry/commands/gem_open.rb +0 -29
  157. data/lib/pry/commands/gist.rb +0 -102
  158. data/lib/pry/commands/install_command.rb +0 -51
  159. data/lib/pry/commands/simple_prompt.rb +0 -22
  160. data/lib/pry/commands.rb +0 -6
  161. data/lib/pry/completion.rb +0 -304
  162. data/lib/pry/custom_completions.rb +0 -6
  163. data/lib/pry/history_array.rb +0 -116
  164. data/lib/pry/plugins.rb +0 -103
  165. data/lib/pry/rbx_method.rb +0 -13
  166. data/lib/pry/rbx_path.rb +0 -22
  167. data/lib/pry/rubygem.rb +0 -74
  168. data/lib/pry/terminal.rb +0 -78
  169. data/lib/pry/test/helper.rb +0 -185
  170. data/man/pry.1 +0 -195
  171. data/man/pry.1.html +0 -204
  172. data/man/pry.1.ronn +0 -141
  173. data/pry.gemspec +0 -30
  174. data/spec/Procfile +0 -3
  175. data/spec/cli_spec.rb +0 -78
  176. data/spec/code_object_spec.rb +0 -277
  177. data/spec/code_spec.rb +0 -219
  178. data/spec/command_helpers_spec.rb +0 -29
  179. data/spec/command_integration_spec.rb +0 -644
  180. data/spec/command_set_spec.rb +0 -627
  181. data/spec/command_spec.rb +0 -821
  182. data/spec/commands/amend_line_spec.rb +0 -247
  183. data/spec/commands/bang_spec.rb +0 -19
  184. data/spec/commands/cat_spec.rb +0 -164
  185. data/spec/commands/cd_spec.rb +0 -250
  186. data/spec/commands/disable_pry_spec.rb +0 -25
  187. data/spec/commands/edit_spec.rb +0 -727
  188. data/spec/commands/exit_all_spec.rb +0 -34
  189. data/spec/commands/exit_program_spec.rb +0 -19
  190. data/spec/commands/exit_spec.rb +0 -34
  191. data/spec/commands/find_method_spec.rb +0 -70
  192. data/spec/commands/gem_list_spec.rb +0 -26
  193. data/spec/commands/gist_spec.rb +0 -79
  194. data/spec/commands/help_spec.rb +0 -56
  195. data/spec/commands/hist_spec.rb +0 -181
  196. data/spec/commands/jump_to_spec.rb +0 -15
  197. data/spec/commands/ls_spec.rb +0 -181
  198. data/spec/commands/play_spec.rb +0 -140
  199. data/spec/commands/raise_up_spec.rb +0 -56
  200. data/spec/commands/save_file_spec.rb +0 -177
  201. data/spec/commands/show_doc_spec.rb +0 -510
  202. data/spec/commands/show_input_spec.rb +0 -17
  203. data/spec/commands/show_source_spec.rb +0 -782
  204. data/spec/commands/whereami_spec.rb +0 -203
  205. data/spec/completion_spec.rb +0 -239
  206. data/spec/control_d_handler_spec.rb +0 -58
  207. data/spec/documentation_helper_spec.rb +0 -73
  208. data/spec/editor_spec.rb +0 -79
  209. data/spec/exception_whitelist_spec.rb +0 -21
  210. data/spec/fixtures/candidate_helper1.rb +0 -11
  211. data/spec/fixtures/candidate_helper2.rb +0 -8
  212. data/spec/fixtures/example.erb +0 -5
  213. data/spec/fixtures/example_nesting.rb +0 -33
  214. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  215. data/spec/fixtures/testrc +0 -2
  216. data/spec/fixtures/testrcbad +0 -2
  217. data/spec/fixtures/whereami_helper.rb +0 -6
  218. data/spec/helper.rb +0 -34
  219. data/spec/helpers/bacon.rb +0 -86
  220. data/spec/helpers/mock_pry.rb +0 -43
  221. data/spec/helpers/table_spec.rb +0 -105
  222. data/spec/history_array_spec.rb +0 -67
  223. data/spec/hooks_spec.rb +0 -522
  224. data/spec/indent_spec.rb +0 -301
  225. data/spec/input_stack_spec.rb +0 -90
  226. data/spec/method_spec.rb +0 -482
  227. data/spec/prompt_spec.rb +0 -60
  228. data/spec/pry_defaults_spec.rb +0 -419
  229. data/spec/pry_history_spec.rb +0 -99
  230. data/spec/pry_output_spec.rb +0 -95
  231. data/spec/pry_spec.rb +0 -504
  232. data/spec/run_command_spec.rb +0 -25
  233. data/spec/sticky_locals_spec.rb +0 -157
  234. data/spec/syntax_checking_spec.rb +0 -81
  235. data/spec/wrapped_module_spec.rb +0 -261
  236. data/wiki/Customizing-pry.md +0 -397
  237. data/wiki/Home.md +0 -4
@@ -1,199 +1,233 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::ShowInfo < Pry::ClassCommand
3
- extend Pry::Helpers::BaseHelpers
4
+ class Command
5
+ class ShowInfo < Pry::ClassCommand
6
+ extend Pry::Helpers::BaseHelpers
4
7
 
5
- command_options :shellwords => false
6
- command_options :requires_gem => "ruby18_source_location" if mri_18?
8
+ command_options shellwords: false, interpolate: false
7
9
 
8
- def setup
9
- require 'ruby18_source_location' if mri_18?
10
- end
10
+ def initialize(*)
11
+ super
11
12
 
12
- def options(opt)
13
- opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count
14
- opt.on :l, "line-numbers", "Show line numbers"
15
- opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)"
16
- opt.on :a, :all, "Show all definitions and monkeypatches of the module/class"
17
- end
13
+ @used_super = nil
14
+ end
18
15
 
19
- def process
20
- code_object = Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
21
- raise CommandError, no_definition_message if !code_object
22
- @original_code_object = code_object
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
23
25
 
24
- if show_all_modules?(code_object)
25
- # show all monkey patches for a module
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)
49
+ end
26
50
 
27
- result = content_and_headers_for_all_module_candidates(code_object)
28
- else
29
- # show a specific code object
30
- co = code_object_with_accessible_source(code_object)
31
- result = content_and_header_for_code_object(co)
51
+ set_file_and_dir_locals(code_object.source_file)
52
+ pry_instance.pager.page result
32
53
  end
33
54
 
34
- set_file_and_dir_locals(code_object.source_file)
35
- stagger_output result
36
- end
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)
37
63
 
38
- # This method checks whether the `code_object` is a WrappedModule,
39
- # if it is, then it returns the first candidate (monkeypatch) with
40
- # accessible source (or docs). If `code_object` is not a WrappedModule (i.e a
41
- # method or a command) then the `code_object` itself is just
42
- # returned.
43
- #
44
- # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
45
- def code_object_with_accessible_source(code_object)
46
- if code_object.is_a?(WrappedModule)
47
64
  candidate = code_object.candidates.find(&:source)
48
- if candidate
49
- return candidate
50
- else
51
- raise CommandError, no_definition_message if !valid_superclass?(code_object)
65
+ return candidate if candidate
52
66
 
53
- @used_super = true
54
- code_object_with_accessible_source(code_object.super)
55
- end
56
- else
57
- 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)
58
71
  end
59
- end
60
72
 
61
- def valid_superclass?(code_object)
62
- code_object.super && code_object.super.wrapped != Object
63
- end
73
+ def valid_superclass?(code_object)
74
+ code_object.super && code_object.super.wrapped != Object
75
+ end
64
76
 
65
- def content_and_header_for_code_object(code_object)
66
- header(code_object) + content_for(code_object)
67
- end
77
+ def content_and_header_for_code_object(code_object)
78
+ header(code_object) + content_for(code_object)
79
+ end
68
80
 
69
- def content_and_headers_for_all_module_candidates(mod)
70
- result = "Found #{mod.number_of_candidates} candidates for `#{mod.name}` definition:\n"
71
- mod.number_of_candidates.times do |v|
72
- candidate = mod.candidate(v)
73
- begin
74
- result << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{candidate.source_file} @ line #{candidate.source_line}:\n"
75
- content = content_for(candidate)
76
-
77
- result << "Number of lines: #{content.lines.count}\n\n" << content
78
- rescue Pry::RescuableException
79
- result << "\nNo content found.\n"
80
- next
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
81
96
  end
97
+ result
82
98
  end
83
- result
84
- end
85
99
 
86
- def no_definition_message
87
- "Couldn't locate a definition for #{obj_name}!"
88
- end
100
+ def no_definition_message
101
+ "Couldn't locate a definition for #{obj_name}"
102
+ end
89
103
 
90
- # Generate a header (meta-data information) for all the code
91
- # object types: methods, modules, commands, procs...
92
- def header(code_object)
93
- file_name, line_num = file_and_line_for(code_object)
94
- h = "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} "
95
- h << code_object_header(code_object, line_num)
96
- h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
97
- "#{content_for(code_object).lines.count}\n\n"
98
- h << Helpers::Text.bold('** Warning:') + " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
99
- h
100
- end
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
101
118
 
102
- def code_object_header(code_object, line_num)
103
- if code_object.real_method_object?
104
- method_header(code_object, line_num)
119
+ if content.lines.none?
120
+ h += bold('** Warning:')
121
+ h += " Cannot find code for '#{code_object.name}' (source_location is nil)"
122
+ end
105
123
 
106
- # It sucks we have to test for both Pry::WrappedModule and WrappedModule::Candidate,
107
- # probably indicates a deep refactor needs to happen in those classes.
108
- elsif code_object.is_a?(Pry::WrappedModule) || code_object.is_a?(Pry::WrappedModule::Candidate)
109
- module_header(code_object, line_num)
110
- else
111
- ""
124
+ h
112
125
  end
113
- end
114
126
 
115
- def method_header(code_object, line_num)
116
- h = ""
117
- h << (code_object.c_method? ? "(C Method):" : "@ line #{line_num}:")
118
- h << method_sections(code_object)[:owner]
119
- h << method_sections(code_object)[:visibility]
120
- h << method_sections(code_object)[:signature]
121
- h
122
- end
127
+ def code_object_header(code_object, line_num)
128
+ if code_object.real_method_object?
129
+ method_header(code_object, line_num)
130
+
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
140
+ end
123
141
 
124
- def module_header(code_object, line_num)
125
- h = ""
126
- h << "@ line #{line_num}:\n"
127
- h << text.bold(code_object.module? ? "Module" : "Class")
128
- h << " #{text.bold('name:')} #{code_object.nonblank_name}"
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
129
150
 
130
- if code_object.number_of_candidates > 1
131
- h << (text.bold("\nNumber of monkeypatches: ") + code_object.number_of_candidates.to_s)
132
- h << ". Use the `-a` option to display all available monkeypatches"
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}"
156
+
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
133
163
  end
134
- h
135
- end
136
164
 
137
- def method_sections(code_object)
138
- {
139
- :owner => "\n#{text.bold("Owner:")} #{code_object.owner || "N/A"}\n",
140
- :visibility => "#{text.bold("Visibility:")} #{code_object.visibility}",
141
- :signature => "\n#{text.bold("Signature:")} #{code_object.signature}"
142
- }.merge(header_options) { |key, old, new| (new && old).to_s }
143
- end
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
144
172
 
145
- def header_options
146
- {
147
- :owner => true,
148
- :visibility => true,
149
- :signature => nil
150
- }
151
- end
173
+ def header_options
174
+ {
175
+ owner: true,
176
+ visibility: true,
177
+ signature: nil
178
+ }
179
+ end
152
180
 
153
- def show_all_modules?(code_object)
154
- code_object.is_a?(Pry::WrappedModule) && opts.present?(:all)
155
- end
181
+ def show_all_modules?(code_object)
182
+ code_object.is_a?(Pry::WrappedModule) && opts.present?(:all)
183
+ end
156
184
 
157
- def obj_name
158
- @obj_name ||= args.empty? ? nil : args.join(" ")
159
- end
185
+ def obj_name
186
+ @obj_name ||= args.empty? ? nil : args.join(' ')
187
+ end
160
188
 
161
- def use_line_numbers?
162
- opts.present?(:b) || opts.present?(:l)
163
- end
189
+ def use_line_numbers?
190
+ opts.present?(:b) || opts.present?(:l)
191
+ end
164
192
 
165
- def start_line_for(code_object)
166
- if opts.present?(:'base-one')
167
- 1
168
- else
169
- code_object.source_line || 1
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
170
199
  end
171
- end
172
200
 
173
- # takes into account possible yard docs, and returns yard_file / yard_line
174
- # Also adjusts for start line of comments (using start_line_for), which it has to infer
175
- # by subtracting number of lines of comment from start line of code_object
176
- def file_and_line_for(code_object)
177
- if code_object.module_with_yard_docs?
178
- [code_object.yard_file, code_object.yard_line]
179
- else
180
- [code_object.source_file, start_line_for(code_object)]
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
181
211
  end
182
- end
183
212
 
184
- def complete(input)
185
- if input =~ /([^ ]*)#([a-z0-9_]*)\z/
186
- prefix, search = [$1, $2]
187
- methods = begin
188
- Pry::Method.all_from_class(binding.eval(prefix))
189
- rescue RescuableException => e
190
- return super
191
- end
192
- methods.map do |method|
193
- [prefix, method.name].join('#') if method.name.start_with?(search)
194
- end.compact
195
- else
196
- super
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
197
231
  end
198
232
  end
199
233
  end
@@ -1,17 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::ShowInput < Pry::ClassCommand
3
- match 'show-input'
4
- group 'Editing'
5
- description 'Show the contents of the input buffer for the current multi-line expression.'
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
- banner <<-'BANNER'
8
- Show the contents of the input buffer for the current multi-line expression.
9
- BANNER
11
+ banner <<-'BANNER'
12
+ Show the contents of the input buffer for the current multi-line expression.
13
+ BANNER
10
14
 
11
- def process
12
- output.puts Code.new(eval_string).with_line_numbers
15
+ def process
16
+ output.puts Code.new(eval_string).with_line_numbers
17
+ end
13
18
  end
14
- end
15
19
 
16
- Pry::Commands.add_command(Pry::Command::ShowInput)
20
+ Pry::Commands.add_command(Pry::Command::ShowInput)
21
+ end
17
22
  end
@@ -1,38 +1,118 @@
1
- require 'pry/commands/show_info'
1
+ # frozen_string_literal: true
2
2
 
3
3
  class Pry
4
- class Command::ShowSource < Command::ShowInfo
5
- match 'show-source'
6
- group 'Introspection'
7
- description 'Show the source for a method or class.'
8
-
9
- banner <<-'BANNER'
10
- Usage: show-source [OPTIONS] [METH|CLASS]
11
- Aliases: $, show-method
12
-
13
- Show the source for a method or class. Tries instance methods first and then
14
- methods by default.
15
-
16
- show-source hi_method
17
- show-source hi_method
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 --super # for superclass of Pry (Object class)
22
-
23
- https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
24
- BANNER
25
-
26
- # The source for code_object prepared for display.
27
- def content_for(code_object)
28
- cannot_locate_source_error if !code_object.source
29
-
30
- Code.new(code_object.source, start_line_for(code_object)).
31
- with_line_numbers(use_line_numbers?).to_s
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.
18
+
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
63
+ end
64
+
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
32
111
  end
33
- end
34
112
 
35
- Pry::Commands.add_command(Pry::Command::ShowSource)
36
- Pry::Commands.alias_command 'show-method', 'show-source'
37
- Pry::Commands.alias_command '$', 'show-source'
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
+ Pry::Commands.alias_command '?', 'show-source -d'
117
+ end
38
118
  end
@@ -1,40 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Stat < Pry::ClassCommand
3
- match 'stat'
4
- group 'Introspection'
5
- description 'View method information and set _file_ and _dir_ locals.'
6
- command_options :shellwords => false
4
+ class Command
5
+ class Stat < Pry::ClassCommand
6
+ match 'stat'
7
+ group 'Introspection'
8
+ description 'View method information and set _file_ and _dir_ locals.'
9
+ command_options shellwords: false
7
10
 
8
- banner <<-'BANNER'
9
- Usage: stat [OPTIONS] [METH]
11
+ banner <<-'BANNER'
12
+ Usage: stat [OPTIONS] [METH]
10
13
 
11
- Show method information for method METH and set _file_ and _dir_ locals.
14
+ Show method information for method METH and set _file_ and _dir_ locals.
12
15
 
13
- stat hello_method
14
- BANNER
16
+ stat hello_method
17
+ BANNER
15
18
 
16
- def options(opt)
17
- method_options(opt)
18
- end
19
+ def options(opt)
20
+ method_options(opt)
21
+ end
22
+
23
+ def process
24
+ meth = method_object
25
+ aliases = meth.aliases
19
26
 
20
- def process
21
- meth = method_object
22
- aliases = meth.aliases
23
-
24
- output.puts unindent <<-EOS
25
- Method Information:
26
- --
27
- Name: #{meth.name}
28
- Alias#{ "es" if aliases.length > 1 }: #{ aliases.any? ? aliases.join(", ") : "None." }
29
- Owner: #{meth.owner ? meth.owner : "Unknown"}
30
- Visibility: #{meth.visibility}
31
- Type: #{meth.is_a?(::Method) ? "Bound" : "Unbound"}
32
- Arity: #{meth.arity}
33
- Method Signature: #{meth.signature}
34
- Source Location: #{meth.source_location ? meth.source_location.join(":") : "Not found."}
35
- EOS
27
+ output.puts(unindent(<<-OUTPUT))
28
+ Method Information:
29
+ --
30
+ Name: #{meth.name}
31
+ Alias#{'es' if aliases.length > 1}: #{aliases.any? ? aliases.join(', ') : 'None.'}
32
+ Owner: #{meth.owner || 'Unknown'}
33
+ Visibility: #{meth.visibility}
34
+ Type: #{meth.is_a?(::Method) ? 'Bound' : 'Unbound'}
35
+ Arity: #{meth.arity}
36
+ Method Signature: #{meth.signature}
37
+ Source Location: #{meth.source_location ? meth.source_location.join(':') : 'Not found.'}
38
+ OUTPUT
39
+ end
36
40
  end
37
- end
38
41
 
39
- Pry::Commands.add_command(Pry::Command::Stat)
42
+ Pry::Commands.add_command(Pry::Command::Stat)
43
+ end
40
44
  end