super-smart-mod 0.0.1

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 (143) hide show
  1. checksums.yaml +7 -0
  2. data/pry-0.16.0/CHANGELOG.md +1211 -0
  3. data/pry-0.16.0/LICENSE +25 -0
  4. data/pry-0.16.0/README.md +469 -0
  5. data/pry-0.16.0/bin/pry +13 -0
  6. data/pry-0.16.0/lib/pry/basic_object.rb +10 -0
  7. data/pry-0.16.0/lib/pry/block_command.rb +22 -0
  8. data/pry-0.16.0/lib/pry/class_command.rb +194 -0
  9. data/pry-0.16.0/lib/pry/cli.rb +211 -0
  10. data/pry-0.16.0/lib/pry/code/code_file.rb +114 -0
  11. data/pry-0.16.0/lib/pry/code/code_range.rb +73 -0
  12. data/pry-0.16.0/lib/pry/code/loc.rb +105 -0
  13. data/pry-0.16.0/lib/pry/code.rb +357 -0
  14. data/pry-0.16.0/lib/pry/code_object.rb +197 -0
  15. data/pry-0.16.0/lib/pry/color_printer.rb +66 -0
  16. data/pry-0.16.0/lib/pry/command.rb +520 -0
  17. data/pry-0.16.0/lib/pry/command_set.rb +418 -0
  18. data/pry-0.16.0/lib/pry/command_state.rb +36 -0
  19. data/pry-0.16.0/lib/pry/commands/amend_line.rb +103 -0
  20. data/pry-0.16.0/lib/pry/commands/bang.rb +24 -0
  21. data/pry-0.16.0/lib/pry/commands/bang_pry.rb +21 -0
  22. data/pry-0.16.0/lib/pry/commands/cat/abstract_formatter.rb +32 -0
  23. data/pry-0.16.0/lib/pry/commands/cat/exception_formatter.rb +90 -0
  24. data/pry-0.16.0/lib/pry/commands/cat/file_formatter.rb +77 -0
  25. data/pry-0.16.0/lib/pry/commands/cat/input_expression_formatter.rb +48 -0
  26. data/pry-0.16.0/lib/pry/commands/cat.rb +70 -0
  27. data/pry-0.16.0/lib/pry/commands/cd.rb +48 -0
  28. data/pry-0.16.0/lib/pry/commands/change_inspector.rb +34 -0
  29. data/pry-0.16.0/lib/pry/commands/change_prompt.rb +51 -0
  30. data/pry-0.16.0/lib/pry/commands/clear_screen.rb +20 -0
  31. data/pry-0.16.0/lib/pry/commands/code_collector.rb +182 -0
  32. data/pry-0.16.0/lib/pry/commands/disable_pry.rb +31 -0
  33. data/pry-0.16.0/lib/pry/commands/easter_eggs.rb +101 -0
  34. data/pry-0.16.0/lib/pry/commands/edit/exception_patcher.rb +29 -0
  35. data/pry-0.16.0/lib/pry/commands/edit/file_and_line_locator.rb +47 -0
  36. data/pry-0.16.0/lib/pry/commands/edit.rb +225 -0
  37. data/pry-0.16.0/lib/pry/commands/exit.rb +47 -0
  38. data/pry-0.16.0/lib/pry/commands/exit_all.rb +33 -0
  39. data/pry-0.16.0/lib/pry/commands/exit_program.rb +27 -0
  40. data/pry-0.16.0/lib/pry/commands/find_method.rb +199 -0
  41. data/pry-0.16.0/lib/pry/commands/fix_indent.rb +23 -0
  42. data/pry-0.16.0/lib/pry/commands/help.rb +171 -0
  43. data/pry-0.16.0/lib/pry/commands/hist.rb +182 -0
  44. data/pry-0.16.0/lib/pry/commands/import_set.rb +27 -0
  45. data/pry-0.16.0/lib/pry/commands/jump_to.rb +33 -0
  46. data/pry-0.16.0/lib/pry/commands/list_inspectors.rb +42 -0
  47. data/pry-0.16.0/lib/pry/commands/ls/config.rb +54 -0
  48. data/pry-0.16.0/lib/pry/commands/ls/constants.rb +75 -0
  49. data/pry-0.16.0/lib/pry/commands/ls/formatter.rb +55 -0
  50. data/pry-0.16.0/lib/pry/commands/ls/globals.rb +50 -0
  51. data/pry-0.16.0/lib/pry/commands/ls/grep.rb +23 -0
  52. data/pry-0.16.0/lib/pry/commands/ls/instance_vars.rb +40 -0
  53. data/pry-0.16.0/lib/pry/commands/ls/interrogatable.rb +24 -0
  54. data/pry-0.16.0/lib/pry/commands/ls/jruby_hacks.rb +55 -0
  55. data/pry-0.16.0/lib/pry/commands/ls/local_names.rb +37 -0
  56. data/pry-0.16.0/lib/pry/commands/ls/local_vars.rb +47 -0
  57. data/pry-0.16.0/lib/pry/commands/ls/ls_entity.rb +65 -0
  58. data/pry-0.16.0/lib/pry/commands/ls/methods.rb +55 -0
  59. data/pry-0.16.0/lib/pry/commands/ls/methods_helper.rb +50 -0
  60. data/pry-0.16.0/lib/pry/commands/ls/self_methods.rb +34 -0
  61. data/pry-0.16.0/lib/pry/commands/ls.rb +114 -0
  62. data/pry-0.16.0/lib/pry/commands/nesting.rb +29 -0
  63. data/pry-0.16.0/lib/pry/commands/play.rb +113 -0
  64. data/pry-0.16.0/lib/pry/commands/pry_backtrace.rb +30 -0
  65. data/pry-0.16.0/lib/pry/commands/pry_version.rb +21 -0
  66. data/pry-0.16.0/lib/pry/commands/raise_up.rb +38 -0
  67. data/pry-0.16.0/lib/pry/commands/reload_code.rb +74 -0
  68. data/pry-0.16.0/lib/pry/commands/reset.rb +22 -0
  69. data/pry-0.16.0/lib/pry/commands/ri.rb +75 -0
  70. data/pry-0.16.0/lib/pry/commands/save_file.rb +63 -0
  71. data/pry-0.16.0/lib/pry/commands/shell_command.rb +75 -0
  72. data/pry-0.16.0/lib/pry/commands/shell_mode.rb +30 -0
  73. data/pry-0.16.0/lib/pry/commands/show_doc.rb +84 -0
  74. data/pry-0.16.0/lib/pry/commands/show_info.rb +234 -0
  75. data/pry-0.16.0/lib/pry/commands/show_input.rb +22 -0
  76. data/pry-0.16.0/lib/pry/commands/show_source.rb +57 -0
  77. data/pry-0.16.0/lib/pry/commands/stat.rb +44 -0
  78. data/pry-0.16.0/lib/pry/commands/switch_to.rb +29 -0
  79. data/pry-0.16.0/lib/pry/commands/toggle_color.rb +28 -0
  80. data/pry-0.16.0/lib/pry/commands/watch_expression/expression.rb +43 -0
  81. data/pry-0.16.0/lib/pry/commands/watch_expression.rb +108 -0
  82. data/pry-0.16.0/lib/pry/commands/whereami.rb +205 -0
  83. data/pry-0.16.0/lib/pry/commands/wtf.rb +95 -0
  84. data/pry-0.16.0/lib/pry/config/attributable.rb +22 -0
  85. data/pry-0.16.0/lib/pry/config/lazy_value.rb +29 -0
  86. data/pry-0.16.0/lib/pry/config/memoized_value.rb +34 -0
  87. data/pry-0.16.0/lib/pry/config/value.rb +24 -0
  88. data/pry-0.16.0/lib/pry/config.rb +321 -0
  89. data/pry-0.16.0/lib/pry/control_d_handler.rb +28 -0
  90. data/pry-0.16.0/lib/pry/core_extensions.rb +144 -0
  91. data/pry-0.16.0/lib/pry/editor.rb +157 -0
  92. data/pry-0.16.0/lib/pry/env.rb +18 -0
  93. data/pry-0.16.0/lib/pry/exception_handler.rb +48 -0
  94. data/pry-0.16.0/lib/pry/exceptions.rb +73 -0
  95. data/pry-0.16.0/lib/pry/forwardable.rb +27 -0
  96. data/pry-0.16.0/lib/pry/helpers/base_helpers.rb +71 -0
  97. data/pry-0.16.0/lib/pry/helpers/command_helpers.rb +146 -0
  98. data/pry-0.16.0/lib/pry/helpers/documentation_helpers.rb +84 -0
  99. data/pry-0.16.0/lib/pry/helpers/options_helpers.rb +34 -0
  100. data/pry-0.16.0/lib/pry/helpers/platform.rb +55 -0
  101. data/pry-0.16.0/lib/pry/helpers/table.rb +121 -0
  102. data/pry-0.16.0/lib/pry/helpers/text.rb +118 -0
  103. data/pry-0.16.0/lib/pry/helpers.rb +8 -0
  104. data/pry-0.16.0/lib/pry/history.rb +153 -0
  105. data/pry-0.16.0/lib/pry/hooks.rb +180 -0
  106. data/pry-0.16.0/lib/pry/indent.rb +414 -0
  107. data/pry-0.16.0/lib/pry/input/simple_stdio.rb +13 -0
  108. data/pry-0.16.0/lib/pry/input_completer.rb +283 -0
  109. data/pry-0.16.0/lib/pry/input_lock.rb +129 -0
  110. data/pry-0.16.0/lib/pry/inspector.rb +39 -0
  111. data/pry-0.16.0/lib/pry/last_exception.rb +61 -0
  112. data/pry-0.16.0/lib/pry/method/disowned.rb +67 -0
  113. data/pry-0.16.0/lib/pry/method/patcher.rb +131 -0
  114. data/pry-0.16.0/lib/pry/method/weird_method_locator.rb +222 -0
  115. data/pry-0.16.0/lib/pry/method.rb +599 -0
  116. data/pry-0.16.0/lib/pry/object_path.rb +91 -0
  117. data/pry-0.16.0/lib/pry/output.rb +136 -0
  118. data/pry-0.16.0/lib/pry/pager.rb +249 -0
  119. data/pry-0.16.0/lib/pry/prompt.rb +214 -0
  120. data/pry-0.16.0/lib/pry/pry_class.rb +371 -0
  121. data/pry-0.16.0/lib/pry/pry_instance.rb +663 -0
  122. data/pry-0.16.0/lib/pry/repl.rb +326 -0
  123. data/pry-0.16.0/lib/pry/repl_file_loader.rb +79 -0
  124. data/pry-0.16.0/lib/pry/ring.rb +89 -0
  125. data/pry-0.16.0/lib/pry/slop/LICENSE +20 -0
  126. data/pry-0.16.0/lib/pry/slop/commands.rb +190 -0
  127. data/pry-0.16.0/lib/pry/slop/option.rb +210 -0
  128. data/pry-0.16.0/lib/pry/slop.rb +672 -0
  129. data/pry-0.16.0/lib/pry/syntax_highlighter.rb +26 -0
  130. data/pry-0.16.0/lib/pry/system_command_handler.rb +17 -0
  131. data/pry-0.16.0/lib/pry/testable/evalable.rb +24 -0
  132. data/pry-0.16.0/lib/pry/testable/mockable.rb +22 -0
  133. data/pry-0.16.0/lib/pry/testable/pry_tester.rb +88 -0
  134. data/pry-0.16.0/lib/pry/testable/utility.rb +34 -0
  135. data/pry-0.16.0/lib/pry/testable/variables.rb +52 -0
  136. data/pry-0.16.0/lib/pry/testable.rb +68 -0
  137. data/pry-0.16.0/lib/pry/version.rb +5 -0
  138. data/pry-0.16.0/lib/pry/warning.rb +20 -0
  139. data/pry-0.16.0/lib/pry/wrapped_module/candidate.rb +145 -0
  140. data/pry-0.16.0/lib/pry/wrapped_module.rb +382 -0
  141. data/pry-0.16.0/lib/pry.rb +148 -0
  142. data/super-smart-mod.gemspec +12 -0
  143. metadata +182 -0
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class Cat
6
+ class ExceptionFormatter < AbstractFormatter
7
+ attr_reader :ex
8
+ attr_reader :opts
9
+ attr_reader :pry_instance
10
+ include Pry::Helpers::Text
11
+
12
+ def initialize(exception, pry_instance, opts)
13
+ @ex = exception
14
+ @opts = opts
15
+ @pry_instance = pry_instance
16
+ end
17
+
18
+ def format
19
+ check_for_errors
20
+ set_file_and_dir_locals(
21
+ backtrace_file, pry_instance, pry_instance.current_context
22
+ )
23
+ code = decorate(
24
+ Pry::Code.from_file(backtrace_file)
25
+ .between(*start_and_end_line_for_code_window)
26
+ .with_marker(backtrace_line)
27
+ )
28
+ "#{header}#{code}"
29
+ end
30
+
31
+ private
32
+
33
+ def code_window_size
34
+ pry_instance.config.default_window_size || 5
35
+ end
36
+
37
+ def backtrace_level
38
+ @backtrace_level ||=
39
+ begin
40
+ bl =
41
+ if opts[:ex].nil?
42
+ ex.bt_index
43
+ else
44
+ ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
45
+ end
46
+
47
+ increment_backtrace_level
48
+ bl
49
+ end
50
+ end
51
+
52
+ def increment_backtrace_level
53
+ ex.inc_bt_index
54
+ end
55
+
56
+ def backtrace_file
57
+ Array(ex.bt_source_location_for(backtrace_level)).first
58
+ end
59
+
60
+ def backtrace_line
61
+ Array(ex.bt_source_location_for(backtrace_level)).last
62
+ end
63
+
64
+ def check_for_errors
65
+ raise CommandError, "No exception found." unless ex
66
+ return if backtrace_file
67
+
68
+ raise CommandError, "The given backtrace level is out of bounds."
69
+ end
70
+
71
+ def start_and_end_line_for_code_window
72
+ start_line = backtrace_line - code_window_size
73
+ start_line = 1 if start_line < 1
74
+
75
+ [start_line, backtrace_line + code_window_size]
76
+ end
77
+
78
+ def header
79
+ unindent(
80
+ "#{bold 'Exception:'} #{ex.class}: #{ex.message}\n" \
81
+ "--\n" \
82
+ "#{bold('From:')} #{backtrace_file}:#{backtrace_line} @ " \
83
+ "#{bold("level: #{backtrace_level}")} of backtrace " \
84
+ "(of #{ex.backtrace.size - 1}).\n\n"
85
+ )
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class Cat
6
+ class FileFormatter < AbstractFormatter
7
+ attr_reader :file_with_embedded_line
8
+ attr_reader :opts
9
+ attr_reader :pry_instance
10
+
11
+ def initialize(file_with_embedded_line, pry_instance, opts)
12
+ unless file_with_embedded_line
13
+ raise CommandError, "Must provide a filename, --in, or --ex."
14
+ end
15
+
16
+ @file_with_embedded_line = file_with_embedded_line
17
+ @opts = opts
18
+ @pry_instance = pry_instance
19
+ @code_from_file = Pry::Code.from_file(file_name)
20
+ end
21
+
22
+ def format
23
+ set_file_and_dir_locals(file_name, pry_instance, pry_instance.current_context)
24
+ decorate(@code_from_file)
25
+ end
26
+
27
+ def file_and_line
28
+ file_name, line_num = file_with_embedded_line.split(%r{:(?!/|\\)})
29
+
30
+ [file_name, line_num ? line_num.to_i : nil]
31
+ end
32
+
33
+ private
34
+
35
+ def file_name
36
+ file_and_line.first
37
+ end
38
+
39
+ def line_number
40
+ file_and_line.last
41
+ end
42
+
43
+ def code_window_size
44
+ pry_instance.config.default_window_size || 7
45
+ end
46
+
47
+ def decorate(content)
48
+ if line_number
49
+ super(content.around(line_number, code_window_size))
50
+ else
51
+ super
52
+ end
53
+ end
54
+
55
+ def code_type
56
+ opts[:type] || detect_code_type_from_file(file_name)
57
+ end
58
+
59
+ def detect_code_type_from_file(file_name)
60
+ code_type = @code_from_file.code_type
61
+
62
+ if code_type == :unknown
63
+ name = File.basename(file_name).split('.', 2).first
64
+ case name
65
+ when "Rakefile", "Gemfile"
66
+ :ruby
67
+ else
68
+ :text
69
+ end
70
+ else
71
+ code_type
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class Cat
6
+ class InputExpressionFormatter < AbstractFormatter
7
+ attr_accessor :input_expressions
8
+ attr_accessor :opts
9
+
10
+ def initialize(input_expressions, opts)
11
+ @input_expressions = input_expressions
12
+ @opts = opts
13
+ end
14
+
15
+ def format
16
+ raise CommandError, "No input expressions!" if numbered_input_items.empty?
17
+
18
+ if numbered_input_items.length > 1
19
+ content = ''
20
+ numbered_input_items.each do |i, s|
21
+ content += "#{Helpers::Text.bold(i.to_s)}:\n"
22
+ content += decorate(Pry::Code(s).with_indentation(2)).to_s
23
+ end
24
+
25
+ content
26
+ else
27
+ decorate(Pry::Code(selected_input_items.first))
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def selected_input_items
34
+ input_expressions[normalized_expression_range] || []
35
+ end
36
+
37
+ def numbered_input_items
38
+ @numbered_input_items ||= normalized_expression_range.zip(selected_input_items)
39
+ .reject { |_, s| s.nil? || s == "" }
40
+ end
41
+
42
+ def normalized_expression_range
43
+ absolute_index_range(opts[:i], input_expressions.count)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class Cat < Pry::ClassCommand
6
+ match 'cat'
7
+ group 'Input and Output'
8
+ description "Show code from a file, Pry's input buffer, or the last exception."
9
+
10
+ banner <<-'BANNER'
11
+ Usage: cat FILE
12
+ cat --ex [STACK_INDEX]
13
+ cat --in [INPUT_INDEX_OR_RANGE]
14
+
15
+ `cat` is capable of showing part or all of a source file, the context of the
16
+ last exception, or an expression from Pry's input history.
17
+
18
+ `cat --ex` defaults to showing the lines surrounding the location of the last
19
+ exception. Invoking it more than once travels up the exception's backtrace, and
20
+ providing a number shows the context of the given index of the backtrace.
21
+ BANNER
22
+
23
+ def options(opt)
24
+ opt.on :ex, "Show the context of the last exception",
25
+ optional_argument: true, as: Integer
26
+ opt.on :i, :in, "Show one or more entries from Pry's expression history",
27
+ optional_argument: true, as: Range, default: -5..-1
28
+ opt.on :s, :start, "Starting line (defaults to the first line)",
29
+ optional_argument: true, as: Integer
30
+ opt.on :e, :end, "Ending line (defaults to the last line)",
31
+ optional_argument: true, as: Integer
32
+ opt.on :l, :'line-numbers', "Show line numbers"
33
+ opt.on :t, :type, "The file type for syntax highlighting " \
34
+ "(e.g., 'ruby' or 'python')",
35
+ argument: true, as: Symbol
36
+ end
37
+
38
+ def process
39
+ output =
40
+ if opts.present?(:ex)
41
+ ExceptionFormatter.new(
42
+ pry_instance.last_exception, pry_instance, opts
43
+ ).format
44
+ elsif opts.present?(:in)
45
+ InputExpressionFormatter.new(pry_instance.input_ring, opts).format
46
+ else
47
+ FileFormatter.new(args.first, pry_instance, opts).format
48
+ end
49
+
50
+ pry_instance.pager.page output
51
+ end
52
+
53
+ def complete(search)
54
+ super | load_path_completions
55
+ end
56
+
57
+ def load_path_completions
58
+ $LOAD_PATH.flat_map do |path|
59
+ Dir[path + '/**/*'].map do |f|
60
+ next if File.directory?(f)
61
+
62
+ f.sub!(path + '/', '')
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ Pry::Commands.add_command(Pry::Command::Cat)
69
+ end
70
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class Cd < Pry::ClassCommand
6
+ match 'cd'
7
+ group 'Context'
8
+ description 'Move into a new context (object or scope).'
9
+
10
+ banner <<-'BANNER'
11
+ Usage: cd [OPTIONS] [--help]
12
+
13
+ Move into new context (object or scope). As in UNIX shells use `cd ..` to go
14
+ back, `cd /` to return to Pry top-level and `cd -` to toggle between last two
15
+ scopes. Complex syntax (e.g `cd ../@x/@y`) also supported.
16
+
17
+ cd @x
18
+ cd ..
19
+ cd /
20
+ cd -
21
+
22
+ https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope
23
+ BANNER
24
+
25
+ command_options state: %i[old_stack]
26
+
27
+ def process
28
+ state.old_stack ||= []
29
+
30
+ if arg_string.strip == "-"
31
+ unless state.old_stack.empty?
32
+ pry_instance.binding_stack, state.old_stack =
33
+ state.old_stack, pry_instance.binding_stack
34
+ end
35
+ else
36
+ stack = ObjectPath.new(arg_string, pry_instance.binding_stack).resolve
37
+
38
+ if stack && stack != pry_instance.binding_stack
39
+ state.old_stack = pry_instance.binding_stack
40
+ pry_instance.binding_stack = stack
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ Pry::Commands.add_command(Pry::Command::Cd)
47
+ end
48
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class ChangeInspector < Pry::ClassCommand
6
+ match 'change-inspector'
7
+ group 'Input and Output'
8
+ description 'Change the current inspector proc.'
9
+ command_options argument_required: true
10
+ banner <<-BANNER
11
+ Usage: change-inspector NAME
12
+
13
+ Change the proc used to print return values. See list-inspectors for a list
14
+ of available procs and a short description of what each one does.
15
+ BANNER
16
+
17
+ def process(inspector)
18
+ unless inspector_map.key?(inspector)
19
+ raise Pry::CommandError, "'#{inspector}' isn't a known inspector!"
20
+ end
21
+
22
+ pry_instance.print = inspector_map[inspector][:value]
23
+ output.puts "Switched to the '#{inspector}' inspector!"
24
+ end
25
+
26
+ private
27
+
28
+ def inspector_map
29
+ Pry::Inspector::MAP
30
+ end
31
+ Pry::Commands.add_command(self)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class ChangePrompt < Pry::ClassCommand
6
+ match 'change-prompt'
7
+ group 'Input and Output'
8
+ description 'Change the current prompt.'
9
+ command_options argument_required: true
10
+ banner <<-BANNER
11
+ Usage: change-prompt [OPTIONS] [NAME]
12
+
13
+ Change the current prompt.
14
+ BANNER
15
+
16
+ def options(opt)
17
+ opt.on(:l, :list, 'List the available prompts')
18
+ end
19
+
20
+ def process(prompt)
21
+ if opts.present?(:l)
22
+ list_prompts
23
+ else
24
+ change_prompt(prompt)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def list_prompts
31
+ prompts = Pry::Prompt.all.map do |name, prompt|
32
+ "#{bold(name)}#{red(' (selected)') if pry_instance.prompt == prompt}\n" +
33
+ prompt.description
34
+ end
35
+ output.puts(prompts.join("\n" * 2))
36
+ end
37
+
38
+ def change_prompt(prompt)
39
+ if Pry::Prompt[prompt]
40
+ pry_instance.prompt = Pry::Prompt[prompt]
41
+ else
42
+ raise Pry::CommandError,
43
+ "'#{prompt}' isn't a known prompt. Run `change-prompt --list` " \
44
+ "to see the list of known prompts."
45
+ end
46
+ end
47
+
48
+ Pry::Commands.add_command(self)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class ClearScreen < Pry::ClassCommand
6
+ match 'clear-screen'
7
+ group 'Input and Output'
8
+ description 'Clear the contents of the screen/window Pry is running in.'
9
+
10
+ def process
11
+ if Pry::Helpers::Platform.windows?
12
+ pry_instance.config.system.call(pry_instance.output, 'cls', pry_instance)
13
+ else
14
+ pry_instance.config.system.call(pry_instance.output, 'clear', pry_instance)
15
+ end
16
+ end
17
+ Pry::Commands.add_command(self)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class CodeCollector
6
+ include Helpers::CommandHelpers
7
+
8
+ attr_reader :args
9
+ attr_reader :opts
10
+ attr_reader :pry_instance
11
+
12
+ # The name of the explicitly given file (if any).
13
+ attr_accessor :file
14
+
15
+ class << self
16
+ attr_accessor :input_expression_ranges
17
+ attr_accessor :output_result_ranges
18
+ end
19
+
20
+ @input_expression_ranges = []
21
+ @output_result_ranges = []
22
+
23
+ def initialize(args, opts, pry_instance)
24
+ @args = args
25
+ @opts = opts
26
+ @pry_instance = pry_instance
27
+ end
28
+
29
+ # Add the `--lines`, `-o`, `-i`, `-s`, `-d` options.
30
+ def self.inject_options(opt)
31
+ @input_expression_ranges = []
32
+ @output_result_ranges = []
33
+
34
+ opt.on :l, :lines, "Restrict to a subset of lines. Takes a line number " \
35
+ "or range",
36
+ optional_argument: true, as: Range, default: 1..-1
37
+ opt.on :o, :out, "Select lines from Pry's output result history. " \
38
+ "Takes an index or range",
39
+ optional_argument: true, as: Range, default: -5..-1 do |r|
40
+ output_result_ranges << (r || (-5..-1))
41
+ end
42
+ opt.on :i, :in, "Select lines from Pry's input expression history. " \
43
+ "Takes an index or range",
44
+ optional_argument: true, as: Range, default: -5..-1 do |r|
45
+ input_expression_ranges << (r || (-5..-1))
46
+ end
47
+ opt.on :s, :super, "Select the 'super' method. Can be repeated to " \
48
+ "traverse the ancestors",
49
+ as: :count
50
+ opt.on :d, :doc, "Select lines from the code object's documentation"
51
+ end
52
+
53
+ # The content (i.e code/docs) for the selected object.
54
+ # If the user provided a bare code object, it returns the source.
55
+ # If the user provided the `-i` or `-o` switches, it returns the
56
+ # selected input/output lines joined as a string. If the user used
57
+ # `-d CODE_OBJECT` it returns the docs for that code object.
58
+ #
59
+ # @return [String]
60
+ def content
61
+ @content ||=
62
+ begin
63
+ if bad_option_combination?
64
+ raise CommandError,
65
+ "Only one of --out, --in, --doc and CODE_OBJECT may " \
66
+ "be specified."
67
+ end
68
+
69
+ content = if opts.present?(:o)
70
+ pry_output_content
71
+ elsif opts.present?(:i)
72
+ pry_input_content
73
+ elsif opts.present?(:d)
74
+ code_object_doc
75
+ else
76
+ code_object_source_or_file
77
+ end
78
+
79
+ restrict_to_lines(content, line_range)
80
+ end
81
+ end
82
+
83
+ # The code object
84
+ #
85
+ # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
86
+ def code_object
87
+ Pry::CodeObject.lookup(obj_name, pry_instance, super: opts[:super])
88
+ end
89
+
90
+ # Given a string and a range, return the `range` lines of that
91
+ # string.
92
+ #
93
+ # @param [String] content
94
+ # @param [Range, Fixnum] range
95
+ # @return [String] The string restricted to the given range
96
+ def restrict_to_lines(content, range)
97
+ Array(content.lines.to_a[range]).join
98
+ end
99
+
100
+ # The selected `pry_instance.output_ring` as a string, as specified by
101
+ # the `-o` switch.
102
+ #
103
+ # @return [String]
104
+ def pry_output_content
105
+ pry_array_content_as_string(
106
+ pry_instance.output_ring,
107
+ self.class.output_result_ranges,
108
+ &:pretty_inspect
109
+ )
110
+ end
111
+
112
+ # The selected `pry_instance.input_ring` as a string, as specified by
113
+ # the `-i` switch.
114
+ #
115
+ # @return [String]
116
+ def pry_input_content
117
+ pry_array_content_as_string(
118
+ pry_instance.input_ring, self.class.input_expression_ranges
119
+ ) { |v| v }
120
+ end
121
+
122
+ # The line range passed to `--lines`, converted to a 0-indexed range.
123
+ def line_range
124
+ opts.present?(:lines) ? one_index_range_or_number(opts[:lines]) : 0..-1
125
+ end
126
+
127
+ # Name of the object argument
128
+ def obj_name
129
+ @obj_name ||= args.empty? ? "" : args.join(" ")
130
+ end
131
+
132
+ private
133
+
134
+ def bad_option_combination?
135
+ [opts.present?(:in), opts.present?(:out),
136
+ !args.empty?].count(true) > 1
137
+ end
138
+
139
+ def pry_array_content_as_string(array, ranges)
140
+ all = ''
141
+ ranges.each do |range|
142
+ if convert_to_range(range).first == 0
143
+ raise CommandError, "Minimum value for range is 1, not 0."
144
+ end
145
+
146
+ ranged_array = Array(array[range]) || []
147
+ ranged_array.compact.each { |v| all += yield(v) }
148
+ end
149
+
150
+ all
151
+ end
152
+
153
+ def code_object_doc
154
+ (code_object && code_object.doc) || could_not_locate(obj_name)
155
+ end
156
+
157
+ def code_object_source_or_file
158
+ (code_object && code_object.source) || file_content
159
+ end
160
+
161
+ def file_content
162
+ if File.exist?(obj_name)
163
+ # Set the file accessor.
164
+ self.file = obj_name
165
+ File.read(obj_name)
166
+ else
167
+ could_not_locate(obj_name)
168
+ end
169
+ end
170
+
171
+ def could_not_locate(name)
172
+ raise CommandError, "Cannot locate: #{name}!"
173
+ end
174
+
175
+ def convert_to_range(range)
176
+ return range if range.is_a?(Range)
177
+
178
+ (range..range)
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class DisablePry < Pry::ClassCommand
6
+ match 'disable-pry'
7
+ group 'Navigating Pry'
8
+ description 'Stops all future calls to pry and exits the current session.'
9
+
10
+ banner <<-'BANNER'
11
+ Usage: disable-pry
12
+
13
+ After this command is run any further calls to pry will immediately return `nil`
14
+ without interrupting the flow of your program. This is particularly useful when
15
+ you've debugged the problem you were having, and now wish the program to run to
16
+ the end.
17
+
18
+ As alternatives, consider using `exit!` to force the current Ruby process
19
+ to quit immediately; or using `edit -p` to remove the `binding.pry`
20
+ from the code.
21
+ BANNER
22
+
23
+ def process
24
+ ENV['DISABLE_PRY'] = 'true'
25
+ pry_instance.run_command "exit"
26
+ end
27
+ end
28
+
29
+ Pry::Commands.add_command(Pry::Command::DisablePry)
30
+ end
31
+ end