pry 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -1
  3. data/LICENSE +1 -1
  4. data/README.md +331 -269
  5. data/bin/pry +5 -0
  6. data/lib/pry.rb +132 -119
  7. data/lib/pry/basic_object.rb +8 -4
  8. data/lib/pry/block_command.rb +22 -0
  9. data/lib/pry/class_command.rb +194 -0
  10. data/lib/pry/cli.rb +43 -51
  11. data/lib/pry/code.rb +40 -28
  12. data/lib/pry/code/code_file.rb +28 -24
  13. data/lib/pry/code/code_range.rb +4 -2
  14. data/lib/pry/code/loc.rb +15 -8
  15. data/lib/pry/code_object.rb +40 -38
  16. data/lib/pry/color_printer.rb +47 -46
  17. data/lib/pry/command.rb +166 -369
  18. data/lib/pry/command_set.rb +76 -73
  19. data/lib/pry/command_state.rb +31 -0
  20. data/lib/pry/commands/amend_line.rb +86 -81
  21. data/lib/pry/commands/bang.rb +18 -14
  22. data/lib/pry/commands/bang_pry.rb +15 -11
  23. data/lib/pry/commands/cat.rb +61 -54
  24. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  25. data/lib/pry/commands/cat/exception_formatter.rb +71 -60
  26. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  28. data/lib/pry/commands/cd.rb +40 -35
  29. data/lib/pry/commands/change_inspector.rb +29 -22
  30. data/lib/pry/commands/change_prompt.rb +44 -39
  31. data/lib/pry/commands/clear_screen.rb +16 -10
  32. data/lib/pry/commands/code_collector.rb +148 -133
  33. data/lib/pry/commands/disable_pry.rb +23 -19
  34. data/lib/pry/commands/easter_eggs.rb +19 -30
  35. data/lib/pry/commands/edit.rb +184 -161
  36. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  37. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  38. data/lib/pry/commands/exit.rb +39 -35
  39. data/lib/pry/commands/exit_all.rb +24 -20
  40. data/lib/pry/commands/exit_program.rb +20 -16
  41. data/lib/pry/commands/find_method.rb +168 -160
  42. data/lib/pry/commands/fix_indent.rb +16 -12
  43. data/lib/pry/commands/help.rb +140 -133
  44. data/lib/pry/commands/hist.rb +151 -150
  45. data/lib/pry/commands/import_set.rb +20 -16
  46. data/lib/pry/commands/jump_to.rb +25 -21
  47. data/lib/pry/commands/list_inspectors.rb +35 -28
  48. data/lib/pry/commands/ls.rb +124 -102
  49. data/lib/pry/commands/ls/constants.rb +59 -42
  50. data/lib/pry/commands/ls/formatter.rb +50 -46
  51. data/lib/pry/commands/ls/globals.rb +38 -34
  52. data/lib/pry/commands/ls/grep.rb +17 -13
  53. data/lib/pry/commands/ls/instance_vars.rb +29 -27
  54. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  55. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  56. data/lib/pry/commands/ls/local_names.rb +26 -22
  57. data/lib/pry/commands/ls/local_vars.rb +38 -28
  58. data/lib/pry/commands/ls/ls_entity.rb +47 -51
  59. data/lib/pry/commands/ls/methods.rb +44 -43
  60. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  61. data/lib/pry/commands/ls/self_methods.rb +23 -22
  62. data/lib/pry/commands/nesting.rb +21 -17
  63. data/lib/pry/commands/play.rb +93 -82
  64. data/lib/pry/commands/pry_backtrace.rb +22 -17
  65. data/lib/pry/commands/pry_version.rb +15 -11
  66. data/lib/pry/commands/raise_up.rb +27 -22
  67. data/lib/pry/commands/reload_code.rb +60 -48
  68. data/lib/pry/commands/reset.rb +16 -12
  69. data/lib/pry/commands/ri.rb +55 -45
  70. data/lib/pry/commands/save_file.rb +45 -43
  71. data/lib/pry/commands/shell_command.rb +51 -51
  72. data/lib/pry/commands/shell_mode.rb +21 -17
  73. data/lib/pry/commands/show_doc.rb +80 -68
  74. data/lib/pry/commands/show_info.rb +189 -171
  75. data/lib/pry/commands/show_input.rb +16 -11
  76. data/lib/pry/commands/show_source.rb +110 -45
  77. data/lib/pry/commands/stat.rb +35 -31
  78. data/lib/pry/commands/switch_to.rb +21 -15
  79. data/lib/pry/commands/toggle_color.rb +20 -16
  80. data/lib/pry/commands/watch_expression.rb +89 -86
  81. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  82. data/lib/pry/commands/whereami.rb +156 -148
  83. data/lib/pry/commands/wtf.rb +75 -50
  84. data/lib/pry/config.rb +307 -25
  85. data/lib/pry/config/attributable.rb +22 -0
  86. data/lib/pry/config/lazy_value.rb +29 -0
  87. data/lib/pry/config/memoized_value.rb +34 -0
  88. data/lib/pry/config/value.rb +24 -0
  89. data/lib/pry/control_d_handler.rb +28 -0
  90. data/lib/pry/core_extensions.rb +9 -7
  91. data/lib/pry/editor.rb +48 -21
  92. data/lib/pry/env.rb +18 -0
  93. data/lib/pry/exception_handler.rb +43 -0
  94. data/lib/pry/exceptions.rb +13 -16
  95. data/lib/pry/forwardable.rb +5 -1
  96. data/lib/pry/helpers.rb +2 -0
  97. data/lib/pry/helpers/base_helpers.rb +68 -197
  98. data/lib/pry/helpers/command_helpers.rb +50 -61
  99. data/lib/pry/helpers/documentation_helpers.rb +20 -13
  100. data/lib/pry/helpers/options_helpers.rb +14 -7
  101. data/lib/pry/helpers/platform.rb +7 -5
  102. data/lib/pry/helpers/table.rb +33 -26
  103. data/lib/pry/helpers/text.rb +17 -14
  104. data/lib/pry/history.rb +48 -56
  105. data/lib/pry/hooks.rb +21 -12
  106. data/lib/pry/indent.rb +54 -50
  107. data/lib/pry/input_completer.rb +248 -230
  108. data/lib/pry/input_lock.rb +8 -9
  109. data/lib/pry/inspector.rb +36 -24
  110. data/lib/pry/last_exception.rb +45 -45
  111. data/lib/pry/method.rb +141 -94
  112. data/lib/pry/method/disowned.rb +16 -4
  113. data/lib/pry/method/patcher.rb +12 -3
  114. data/lib/pry/method/weird_method_locator.rb +68 -44
  115. data/lib/pry/object_path.rb +33 -25
  116. data/lib/pry/output.rb +121 -35
  117. data/lib/pry/pager.rb +186 -180
  118. data/lib/pry/prompt.rb +123 -54
  119. data/lib/pry/pry_class.rb +61 -103
  120. data/lib/pry/pry_instance.rb +217 -215
  121. data/lib/pry/repl.rb +18 -22
  122. data/lib/pry/repl_file_loader.rb +27 -21
  123. data/lib/pry/ring.rb +11 -6
  124. data/lib/pry/slop.rb +574 -563
  125. data/lib/pry/slop/commands.rb +164 -169
  126. data/lib/pry/slop/option.rb +172 -168
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable.rb +59 -61
  130. data/lib/pry/testable/evalable.rb +21 -12
  131. data/lib/pry/testable/mockable.rb +18 -10
  132. data/lib/pry/testable/pry_tester.rb +71 -56
  133. data/lib/pry/testable/utility.rb +29 -21
  134. data/lib/pry/testable/variables.rb +49 -43
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +27 -0
  137. data/lib/pry/wrapped_module.rb +51 -42
  138. data/lib/pry/wrapped_module/candidate.rb +21 -14
  139. metadata +35 -35
  140. data/lib/pry/commands.rb +0 -6
  141. data/lib/pry/commands/disabled_commands.rb +0 -2
  142. data/lib/pry/commands/gem_cd.rb +0 -26
  143. data/lib/pry/commands/gem_install.rb +0 -32
  144. data/lib/pry/commands/gem_list.rb +0 -33
  145. data/lib/pry/commands/gem_open.rb +0 -29
  146. data/lib/pry/commands/gem_readme.rb +0 -25
  147. data/lib/pry/commands/gem_search.rb +0 -40
  148. data/lib/pry/commands/gem_stats.rb +0 -83
  149. data/lib/pry/commands/gist.rb +0 -102
  150. data/lib/pry/commands/install_command.rb +0 -54
  151. data/lib/pry/config/behavior.rb +0 -255
  152. data/lib/pry/config/convenience.rb +0 -28
  153. data/lib/pry/config/default.rb +0 -159
  154. data/lib/pry/config/memoization.rb +0 -48
  155. data/lib/pry/platform.rb +0 -91
  156. data/lib/pry/plugins.rb +0 -122
  157. data/lib/pry/rubygem.rb +0 -84
  158. data/lib/pry/terminal.rb +0 -91
@@ -1,18 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Reset < Pry::ClassCommand
3
- match 'reset'
4
- group 'Context'
5
- description 'Reset the REPL to a clean state.'
4
+ class Command
5
+ class Reset < Pry::ClassCommand
6
+ match 'reset'
7
+ group 'Context'
8
+ description 'Reset the REPL to a clean state.'
6
9
 
7
- banner <<-'BANNER'
8
- Reset the REPL to a clean state.
9
- BANNER
10
+ banner <<-'BANNER'
11
+ Reset the REPL to a clean state.
12
+ BANNER
10
13
 
11
- def process
12
- output.puts 'Pry reset.'
13
- exec 'pry'
14
+ def process
15
+ output.puts 'Pry reset.'
16
+ exec 'pry'
17
+ end
14
18
  end
15
- end
16
19
 
17
- Pry::Commands.add_command(Pry::Command::Reset)
20
+ Pry::Commands.add_command(Pry::Command::Reset)
21
+ end
18
22
  end
@@ -1,65 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
1
5
  class Pry
2
- class Command::Ri < Pry::ClassCommand
3
- match 'ri'
4
- group 'Introspection'
5
- description 'View ri documentation.'
6
+ class Command
7
+ class Ri < Pry::ClassCommand
8
+ match 'ri'
9
+ group 'Introspection'
10
+ description 'View ri documentation.'
6
11
 
7
- banner <<-'BANNER'
8
- Usage: ri [spec]
12
+ banner <<-'BANNER'
13
+ Usage: ri [spec]
9
14
 
10
- View ri documentation. Relies on the "rdoc" gem being installed.
11
- See also "show-doc" command.
15
+ View ri documentation. Relies on the "rdoc" gem being installed.
16
+ See also "show-doc" command.
12
17
 
13
- ri Array#each
14
- BANNER
18
+ ri Array#each
19
+ BANNER
15
20
 
16
- def process(spec)
17
- unless spec
18
- return output.puts "Please provide a class, module, or method name (e.g: ri Array#push)"
19
- end
21
+ def process(spec)
22
+ unless spec
23
+ return output.puts(
24
+ "Please provide a class, module, or method name (e.g: ri Array#push)"
25
+ )
26
+ end
20
27
 
21
- # Lazily load RI
22
- require 'rdoc/ri/driver'
28
+ # Lazily load RI
29
+ require 'rdoc/ri/driver'
23
30
 
24
- unless defined? RDoc::RI::PryDriver
31
+ unless defined? RDoc::RI::PryDriver
25
32
 
26
- # Subclass RI so that it formats its output nicely, and uses `lesspipe`.
27
- subclass = Class.new(RDoc::RI::Driver) # the hard way.
33
+ # Subclass RI so that it formats its output nicely, and uses `lesspipe`.
34
+ subclass = Class.new(RDoc::RI::Driver) # the hard way.
28
35
 
29
- subclass.class_eval do
30
- def initialize(pager, opts)
31
- @pager = pager
32
- super opts
33
- end
36
+ subclass.class_eval do
37
+ def initialize(pager, opts)
38
+ @pager = pager
39
+ super opts
40
+ end
34
41
 
35
- def page
36
- paging_text = StringIO.new
37
- yield paging_text
38
- @pager.page(paging_text.string)
39
- end
42
+ def page
43
+ paging_text = StringIO.new
44
+ yield paging_text
45
+ @pager.page(paging_text.string)
46
+ end
40
47
 
41
- def formatter(_io)
42
- if @formatter_klass
43
- @formatter_klass.new
44
- else
45
- RDoc::Markup::ToAnsi.new
48
+ def formatter(_io)
49
+ if @formatter_klass
50
+ @formatter_klass.new
51
+ else
52
+ RDoc::Markup::ToAnsi.new
53
+ end
46
54
  end
47
55
  end
48
- end
49
56
 
50
- RDoc::RI.const_set :PryDriver, subclass # hook it up!
51
- end
57
+ RDoc::RI.const_set :PryDriver, subclass # hook it up!
58
+ end
52
59
 
53
- # Spin-up an RI insance.
54
- ri = RDoc::RI::PryDriver.new _pry_.pager, use_stdout: true, interactive: false
60
+ # Spin-up an RI insance.
61
+ ri = RDoc::RI::PryDriver.new(
62
+ pry_instance.pager, use_stdout: true, interactive: false
63
+ )
55
64
 
56
- begin
57
- ri.display_names [spec] # Get the documentation (finally!)
58
- rescue RDoc::RI::Driver::NotFoundError => e
59
- output.puts "error: '#{e.name}' not found"
65
+ begin
66
+ ri.display_names [spec] # Get the documentation (finally!)
67
+ rescue RDoc::RI::Driver::NotFoundError => e
68
+ output.puts "error: '#{e.name}' not found"
69
+ end
60
70
  end
61
71
  end
62
- end
63
72
 
64
- Pry::Commands.add_command(Pry::Command::Ri)
73
+ Pry::Commands.add_command(Pry::Command::Ri)
74
+ end
65
75
  end
@@ -1,61 +1,63 @@
1
- require 'pry/commands/code_collector'
1
+ # frozen_string_literal: true
2
2
 
3
3
  class Pry
4
- class Command::SaveFile < Pry::ClassCommand
5
- match 'save-file'
6
- group 'Input and Output'
7
- description 'Export to a file using content from the REPL.'
4
+ class Command
5
+ class SaveFile < Pry::ClassCommand
6
+ match 'save-file'
7
+ group 'Input and Output'
8
+ description 'Export to a file using content from the REPL.'
8
9
 
9
- banner <<-'BANNER'
10
- Usage: save-file [OPTIONS] --to [FILE]
10
+ banner <<-'BANNER'
11
+ Usage: save-file [OPTIONS] --to [FILE]
11
12
 
12
- Export to a file using content from the REPL.
13
+ Export to a file using content from the REPL.
13
14
 
14
- save-file my_method --to hello.rb
15
- save-file -i 1..10 --to hello.rb --append
16
- save-file show-method --to my_command.rb
17
- save-file sample_file.rb --lines 2..10 --to output_file.rb
18
- BANNER
15
+ save-file my_method --to hello.rb
16
+ save-file -i 1..10 --to hello.rb --append
17
+ save-file show-method --to my_command.rb
18
+ save-file sample_file.rb --lines 2..10 --to output_file.rb
19
+ BANNER
19
20
 
20
- def options(opt)
21
- CodeCollector.inject_options(opt)
21
+ def options(opt)
22
+ CodeCollector.inject_options(opt)
22
23
 
23
- opt.on :to=, "Specify the output file path"
24
- opt.on :a, :append, "Append output to file"
25
- end
24
+ opt.on :to=, "Specify the output file path"
25
+ opt.on :a, :append, "Append output to file"
26
+ end
26
27
 
27
- def process
28
- @cc = CodeCollector.new(args, opts, _pry_)
29
- raise CommandError, "Found no code to save." if @cc.content.empty?
28
+ def process
29
+ @cc = CodeCollector.new(args, opts, pry_instance)
30
+ raise CommandError, "Found no code to save." if @cc.content.empty?
30
31
 
31
- if !file_name
32
- display_content
33
- else
34
- save_file
32
+ if !file_name
33
+ display_content
34
+ else
35
+ save_file
36
+ end
35
37
  end
36
- end
37
38
 
38
- def file_name
39
- opts[:to] || nil
40
- end
39
+ def file_name
40
+ opts[:to] || nil
41
+ end
41
42
 
42
- def save_file
43
- File.open(file_name, mode) do |f|
44
- f.puts @cc.content
43
+ def save_file
44
+ File.open(file_name, mode) do |f|
45
+ f.puts @cc.content
46
+ end
47
+ output.puts "#{file_name} successfully saved"
45
48
  end
46
- output.puts "#{file_name} successfully saved"
47
- end
48
49
 
49
- def display_content
50
- output.puts @cc.content
51
- output.puts "\n\n--\nPlease use `--to FILE` to export to a file."
52
- output.puts "No file saved!\n--"
53
- end
50
+ def display_content
51
+ output.puts @cc.content
52
+ output.puts "\n\n--\nPlease use `--to FILE` to export to a file."
53
+ output.puts "No file saved!\n--"
54
+ end
54
55
 
55
- def mode
56
- opts.present?(:append) ? "a" : "w"
56
+ def mode
57
+ opts.present?(:append) ? "a" : "w"
58
+ end
57
59
  end
58
- end
59
60
 
60
- Pry::Commands.add_command(Pry::Command::SaveFile)
61
+ Pry::Commands.add_command(Pry::Command::SaveFile)
62
+ end
61
63
  end
@@ -1,75 +1,75 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::ShellCommand < Pry::ClassCommand
3
- match(/\.(.*)/)
4
- group 'Input and Output'
5
- description "All text following a '.' is forwarded to the shell."
6
- command_options listing: '.<shell command>', use_prefix: false,
7
- takes_block: true
8
-
9
- banner <<-'BANNER'
10
- Usage: .COMMAND_NAME
11
-
12
- All text following a "." is forwarded to the shell.
13
-
14
- .ls -aF
15
- .uname
16
- BANNER
17
-
18
- def process(cmd)
19
- if cmd =~ /^cd\s*(.*)/i
20
- process_cd parse_destination($1)
21
- else
22
- pass_block(cmd)
23
- if command_block
24
- command_block.call `#{cmd}`
4
+ class Command
5
+ class ShellCommand < Pry::ClassCommand
6
+ match(/\.(.*)/)
7
+ group 'Input and Output'
8
+ description "All text following a '.' is forwarded to the shell."
9
+ command_options listing: '.<shell command>', use_prefix: false,
10
+ takes_block: true
11
+
12
+ banner <<-'BANNER'
13
+ Usage: .COMMAND_NAME
14
+
15
+ All text following a "." is forwarded to the shell.
16
+
17
+ .ls -aF
18
+ .uname
19
+ BANNER
20
+
21
+ def process(cmd)
22
+ if cmd =~ /^cd\s*(.*)/i
23
+ process_cd parse_destination(Regexp.last_match(1))
25
24
  else
26
- _pry_.config.system.call(output, cmd, _pry_)
25
+ pass_block(cmd)
26
+ if command_block
27
+ command_block.call `#{cmd}`
28
+ else
29
+ pry_instance.config.system.call(output, cmd, pry_instance)
30
+ end
27
31
  end
28
32
  end
29
- end
30
33
 
31
- private
34
+ private
32
35
 
33
- def parse_destination(dest)
34
- return "~" if dest.empty?
35
- return dest unless dest == "-"
36
+ def parse_destination(dest)
37
+ return "~" if dest.empty?
38
+ return dest unless dest == "-"
36
39
 
37
- state.old_pwd || raise(CommandError, "No prior directory available")
38
- end
40
+ state.old_pwd || raise(CommandError, "No prior directory available")
41
+ end
39
42
 
40
- def process_cd(dest)
41
- begin
43
+ def process_cd(dest)
42
44
  state.old_pwd = Dir.pwd
43
45
  Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest))
44
46
  rescue Errno::ENOENT
45
47
  raise CommandError, "No such directory: #{dest}"
46
48
  end
47
- end
48
49
 
49
- def cd_path_env
50
- ENV['CDPATH']
51
- end
50
+ def cd_path_env
51
+ Pry::Env['CDPATH']
52
+ end
52
53
 
53
- def cd_path_exists?
54
- cd_path_env && cd_path_env.length.nonzero?
55
- end
54
+ def cd_path_exists?
55
+ cd_path_env && cd_path_env.length.nonzero?
56
+ end
56
57
 
57
- def path_from_cd_path(dest)
58
- return if !(dest && cd_path_exists?) || special_case_path?(dest)
58
+ def path_from_cd_path(dest)
59
+ return if !(dest && cd_path_exists?) || special_case_path?(dest)
59
60
 
60
- cd_path_env.split(File::PATH_SEPARATOR).each do |path|
61
- if File.directory?(path) && path.split(File::SEPARATOR).last == dest
62
- return path
61
+ cd_path_env.split(File::PATH_SEPARATOR).each do |path|
62
+ return path if File.directory?(path) && path.split(File::SEPARATOR).last == dest
63
63
  end
64
+
65
+ nil
64
66
  end
65
67
 
66
- return nil
68
+ def special_case_path?(dest)
69
+ ['.', '..', '-'].include?(dest) || dest =~ /\A[#{File::PATH_SEPARATOR}~]/
70
+ end
67
71
  end
68
72
 
69
- def special_case_path?(dest)
70
- ['.', '..', '-'].include?(dest) || dest =~ /\A[#{File::PATH_SEPARATOR}~]/
71
- end
73
+ Pry::Commands.add_command(Pry::Command::ShellCommand)
72
74
  end
73
-
74
- Pry::Commands.add_command(Pry::Command::ShellCommand)
75
75
  end
@@ -1,25 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::ShellMode < Pry::ClassCommand
3
- match 'shell-mode'
4
- group 'Input and Output'
5
- description 'Toggle shell mode. Bring in pwd prompt and file completion.'
4
+ class Command
5
+ class ShellMode < Pry::ClassCommand
6
+ match 'shell-mode'
7
+ group 'Input and Output'
8
+ description 'Toggle shell mode. Bring in pwd prompt and file completion.'
6
9
 
7
- banner <<-'BANNER'
8
- Toggle shell mode. Bring in pwd prompt and file completion.
9
- BANNER
10
+ banner <<-'BANNER'
11
+ Toggle shell mode. Bring in pwd prompt and file completion.
12
+ BANNER
10
13
 
11
- def process
12
- state.disabled ^= true
14
+ def process
15
+ state.disabled ^= true
13
16
 
14
- if state.disabled
15
- state.prev_prompt = _pry_.prompt
16
- _pry_.prompt = Pry::Prompt[:shell][:value]
17
- else
18
- _pry_.prompt = state.prev_prompt
17
+ if state.disabled
18
+ state.prev_prompt = pry_instance.prompt
19
+ pry_instance.prompt = Pry::Prompt[:shell]
20
+ else
21
+ pry_instance.prompt = state.prev_prompt
22
+ end
19
23
  end
20
24
  end
21
- end
22
25
 
23
- Pry::Commands.add_command(Pry::Command::ShellMode)
24
- Pry::Commands.alias_command 'file-mode', 'shell-mode'
26
+ Pry::Commands.add_command(Pry::Command::ShellMode)
27
+ Pry::Commands.alias_command 'file-mode', 'shell-mode'
28
+ end
25
29
  end
@@ -1,81 +1,93 @@
1
- require 'pry/commands/show_info'
1
+ # frozen_string_literal: true
2
2
 
3
3
  class Pry
4
- class Command::ShowDoc < Command::ShowInfo
5
- include Pry::Helpers::DocumentationHelpers
6
-
7
- match 'show-doc'
8
- group 'Introspection'
9
- description 'Show the documentation for a method or class.'
10
-
11
- banner <<-BANNER
12
- Usage: show-doc [OPTIONS] [METH]
13
- Aliases: ?
14
-
15
- Show the documentation for a method or class. Tries instance methods first and
16
- then methods by default.
17
-
18
- show-doc hi_method # docs for hi_method
19
- show-doc Pry # for Pry class
20
- show-doc Pry -a # for all definitions of Pry class (all monkey patches)
21
- BANNER
22
-
23
- # The docs for code_object prepared for display.
24
- def content_for(code_object)
25
- Code.new(render_doc_markup_for(code_object),
26
- start_line_for(code_object), :text).
27
- with_line_numbers(use_line_numbers?).to_s
28
- end
4
+ class Command
5
+ class ShowDoc < Command::ShowInfo
6
+ include Pry::Helpers::DocumentationHelpers
7
+
8
+ match 'show-doc'
9
+ group 'Introspection'
10
+ description 'Show the documentation for a method or class.'
11
+
12
+ banner <<-BANNER
13
+ Usage: show-doc [OPTIONS] [METH]
14
+ Aliases: ?
15
+
16
+ Show the documentation for a method or class. Tries instance methods first and
17
+ then methods by default.
18
+
19
+ show-doc hi_method # docs for hi_method
20
+ show-doc Pry # for Pry class
21
+ show-doc Pry -a # for all definitions of Pry class (all monkey patches)
22
+ BANNER
23
+
24
+ def process
25
+ super
26
+
27
+ output.puts(
28
+ "\nWARNING: the show-doc command is deprecated. It will be removed " \
29
+ "from future Pry versions.\nPlease use 'show-source' with the -d " \
30
+ "(or --doc) switch instead\nExample: show-source #{obj_name} -d"
31
+ )
32
+ end
33
+
34
+ # The docs for code_object prepared for display.
35
+ def content_for(code_object)
36
+ Code.new(
37
+ render_doc_markup_for(code_object),
38
+ start_line_for(code_object),
39
+ :text
40
+ ).with_line_numbers(use_line_numbers?).to_s
41
+ end
29
42
 
30
- # process the markup (if necessary) and apply colors
31
- def render_doc_markup_for(code_object)
32
- docs = docs_for(code_object)
33
-
34
- if code_object.command?
35
- # command '--help' shouldn't use markup highlighting
36
- docs
37
- else
38
- if docs.empty?
39
- raise CommandError, "No docs found for: #{
40
- obj_name ? obj_name : 'current context'
41
- }"
43
+ # process the markup (if necessary) and apply colors
44
+ def render_doc_markup_for(code_object)
45
+ docs = docs_for(code_object)
46
+
47
+ if code_object.command?
48
+ # command '--help' shouldn't use markup highlighting
49
+ docs
50
+ else
51
+ if docs.empty?
52
+ raise CommandError, "No docs found for: #{obj_name || 'current context'}"
53
+ end
54
+
55
+ process_comment_markup(docs)
42
56
  end
43
- process_comment_markup(docs)
44
57
  end
45
- end
46
58
 
47
- # Return docs for the code_object, adjusting for whether the code_object
48
- # has yard docs available, in which case it returns those.
49
- # (note we only have to check yard docs for modules since they can
50
- # have multiple docs, but methods can only be doc'd once so we
51
- # dont need to check them)
52
- def docs_for(code_object)
53
- if code_object.module_with_yard_docs?
54
- # yard docs
55
- code_object.yard_doc
56
- else
57
- # normal docs (i.e comments above method/module/command)
58
- code_object.doc
59
+ # Return docs for the code_object, adjusting for whether the code_object
60
+ # has yard docs available, in which case it returns those.
61
+ # (note we only have to check yard docs for modules since they can
62
+ # have multiple docs, but methods can only be doc'd once so we
63
+ # dont need to check them)
64
+ def docs_for(code_object)
65
+ if code_object.module_with_yard_docs?
66
+ # yard docs
67
+ code_object.yard_doc
68
+ else
69
+ # normal docs (i.e comments above method/module/command)
70
+ code_object.doc
71
+ end
59
72
  end
60
- end
61
73
 
62
- # Which sections to include in the 'header', can toggle: :owner,
63
- # :signature and visibility.
64
- def header_options
65
- super.merge signature: true
66
- end
74
+ # Which sections to include in the 'header', can toggle: :owner,
75
+ # :signature and visibility.
76
+ def header_options
77
+ super.merge signature: true
78
+ end
67
79
 
68
- # figure out start line of docs by back-calculating based on
69
- # number of lines in the comment and the start line of the code_object
70
- # @return [Fixnum] start line of docs
71
- def start_line_for(code_object)
72
- return 1 if code_object.command? || opts.present?(:'base-one')
73
- return 1 unless code_object.source_line
80
+ # figure out start line of docs by back-calculating based on
81
+ # number of lines in the comment and the start line of the code_object
82
+ # @return [Fixnum] start line of docs
83
+ def start_line_for(code_object)
84
+ return 1 if code_object.command? || opts.present?(:'base-one')
85
+ return 1 unless code_object.source_line
74
86
 
75
- code_object.source_line - code_object.doc.lines.count
87
+ code_object.source_line - code_object.doc.lines.count
88
+ end
76
89
  end
77
- end
78
90
 
79
- Pry::Commands.add_command(Pry::Command::ShowDoc)
80
- Pry::Commands.alias_command '?', 'show-doc'
91
+ Pry::Commands.add_command(Pry::Command::ShowDoc)
92
+ end
81
93
  end