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,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # @api private
5
+ # @since v0.13.0
6
+ module ExceptionHandler
7
+ class << self
8
+ # Will only show the first line of the backtrace.
9
+ def handle_exception(output, exception, _pry_instance)
10
+ if exception.is_a?(UserError) && exception.is_a?(SyntaxError)
11
+ output.puts "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}"
12
+ else
13
+ output.puts standard_error_text_for(exception)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def standard_error_text_for(exception)
20
+ text = exception_text(exception)
21
+ return text unless exception.respond_to?(:cause)
22
+
23
+ cause = exception.cause
24
+ while cause
25
+ text += cause_text(cause)
26
+ cause = cause.cause
27
+ end
28
+
29
+ text
30
+ end
31
+
32
+ def exception_text(exception)
33
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
34
+ "#{exception.class}: #{exception.message}\n" \
35
+ "from #{exception.backtrace.first}\n"
36
+ else
37
+ "#{exception.class}: #{exception.detailed_message}\n" \
38
+ "from #{exception.backtrace.first}\n"
39
+ end
40
+ end
41
+
42
+ def cause_text(cause)
43
+ "Caused by #{cause.class}: #{cause}\n" \
44
+ "from #{cause.backtrace.first}\n"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # As a REPL, we often want to catch any unexpected exceptions that may have
5
+ # been raised; however we don't want to go overboard and prevent the user
6
+ # from exiting Pry when they want to.
7
+ module RescuableException
8
+ def self.===(exception)
9
+ case exception
10
+ # Catch when the user hits ^C (Interrupt < SignalException), and assume
11
+ # that they just wanted to stop the in-progress command (just like bash
12
+ # etc.)
13
+ when Interrupt
14
+ true
15
+ # Don't catch signals (particularly not SIGTERM) as these are unlikely
16
+ # to be intended for pry itself. We should also make sure that
17
+ # Kernel#exit works.
18
+ when *Pry.config.unrescued_exceptions
19
+ false
20
+ # All other exceptions will be caught.
21
+ else
22
+ true
23
+ end
24
+ end
25
+ end
26
+
27
+ # Catches SecurityErrors if $SAFE is set
28
+ module TooSafeException
29
+ def self.===(exception)
30
+ if Pry::HAS_SAFE_LEVEL
31
+ $SAFE > 0 && exception.is_a?(SecurityError)
32
+ else
33
+ exception.is_a?(SecurityError)
34
+ end
35
+ end
36
+ end
37
+
38
+ # An Exception Tag (cf. Exceptional Ruby) that instructs Pry to show the error
39
+ # in a more user-friendly manner. This should be used when the exception
40
+ # happens within Pry itself as a direct consequence of the user typing
41
+ # something wrong.
42
+ #
43
+ # This allows us to distinguish between the user typing:
44
+ #
45
+ # pry(main)> def )
46
+ # SyntaxError: unexpected )
47
+ #
48
+ # pry(main)> method_that_evals("def )")
49
+ # SyntaxError: (eval):1: syntax error, unexpected ')'
50
+ # from ./a.rb:2 in `eval'
51
+ module UserError; end
52
+
53
+ # When we try to get a binding for an object, we try to define a method on
54
+ # that Object's singleton class. This doesn't work for "frozen" Object's, and
55
+ # the exception is just a vanilla RuntimeError.
56
+ module FrozenObjectException
57
+ def self.===(exception)
58
+ [
59
+ "can't modify frozen class/module",
60
+ "can't modify frozen Class",
61
+ "can't modify frozen object"
62
+ ].include?(exception.message)
63
+ end
64
+ end
65
+
66
+ # CommandErrors are caught by the REPL loop and displayed to the user. They
67
+ # indicate an exceptional condition that's fatal to the current command.
68
+ class CommandError < StandardError; end
69
+ class MethodNotFound < CommandError; end
70
+
71
+ # indicates obsolete API
72
+ class ObsoleteError < StandardError; end
73
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Forwardable
5
+ require 'forwardable'
6
+ include ::Forwardable
7
+
8
+ #
9
+ # Since Ruby 2.4, Forwardable will print a warning when
10
+ # calling a method that is private on a delegate, and
11
+ # in the future it could be an error: https://bugs.ruby-lang.org/issues/12782#note-3
12
+ #
13
+ # That's why we revert to a custom implementation for delegating one
14
+ # private method to another.
15
+ #
16
+ def def_private_delegators(target, *private_delegates)
17
+ private_delegates.each do |private_delegate|
18
+ define_method(private_delegate) do |*a, &b|
19
+ instance_variable_get(target).__send__(private_delegate, *a, &b)
20
+ end
21
+ end
22
+ class_eval do
23
+ private(*private_delegates) # rubocop:disable Style/AccessModifierDeclarations
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Helpers
5
+ module BaseHelpers
6
+ extend self
7
+
8
+ def silence_warnings
9
+ old_verbose = $VERBOSE
10
+ $VERBOSE = nil
11
+ begin
12
+ yield
13
+ ensure
14
+ $VERBOSE = old_verbose
15
+ end
16
+ end
17
+
18
+ # Acts like send but ignores any methods defined below Object or Class in the
19
+ # inheritance hierarchy.
20
+ # This is required to introspect methods on objects like Net::HTTP::Get that
21
+ # have overridden the `method` method.
22
+ def safe_send(obj, method, *args, &block)
23
+ (obj.is_a?(Module) ? Module : Object).instance_method(method)
24
+ .bind(obj).call(*args, &block)
25
+ end
26
+
27
+ def find_command(name, set = Pry::Commands)
28
+ command_match = set.find do |_, command|
29
+ (listing = command.options[:listing]) == name && !listing.nil?
30
+ end
31
+ command_match.last if command_match
32
+ end
33
+
34
+ def not_a_real_file?(file)
35
+ file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
36
+ end
37
+
38
+ def use_ansi_codes?
39
+ Pry::Helpers::Platform.windows_ansi? ||
40
+ ((term = Pry::Env['TERM']) && term != "dumb")
41
+ end
42
+
43
+ def colorize_code(code)
44
+ SyntaxHighlighter.highlight(code)
45
+ end
46
+
47
+ def highlight(string, regexp, highlight_color = :bright_yellow)
48
+ string.gsub(regexp) do |match|
49
+ "<#{highlight_color}>#{match}</#{highlight_color}>"
50
+ end
51
+ end
52
+
53
+ # formatting
54
+ def heading(text)
55
+ text = "#{text}\n--"
56
+ "\e[1m#{text}\e[0m"
57
+ end
58
+
59
+ # Send the given text through the best available pager (if Pry.config.pager is
60
+ # enabled). Infers where to send the output if used as a mixin.
61
+ # DEPRECATED.
62
+ def stagger_output(text, _out = nil)
63
+ if defined?(pry_instance) && pry_instance
64
+ pry_instance.pager.page text
65
+ else
66
+ Pry.new.pager.page text
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+
5
+ class Pry
6
+ module Helpers
7
+ module CommandHelpers
8
+ include OptionsHelpers
9
+
10
+ extend self
11
+
12
+ # Open a temp file and yield it to the block, closing it after
13
+ # @return [String] The path of the temp file
14
+ def temp_file(ext = '.rb')
15
+ file = Tempfile.new(['pry', ext])
16
+ yield(file)
17
+ ensure
18
+ file.close(true)
19
+ end
20
+
21
+ def internal_binding?(context)
22
+ method_name = context.eval("::Kernel.__method__").to_s
23
+ # class_eval is here because of http://jira.codehaus.org/browse/JRUBY-6753
24
+ %w[__binding__ __pry__ class_eval].include?(method_name)
25
+ # TODO: codehaus is dead, there was no test for this and the
26
+ # description for the commit doesn't exist. Probably a candidate for
27
+ # removal so we have a chance to introduce a regression and document it
28
+ # properly.
29
+ end
30
+
31
+ def get_method_or_raise(method_name, context, opts = {})
32
+ method = Pry::Method.from_str(method_name, context, opts)
33
+ if !method && method_name
34
+ raise Pry::MethodNotFound, "method '#{method_name}' could not be found."
35
+ end
36
+
37
+ (opts[:super] || 0).times do
38
+ if method.super
39
+ method = method.super
40
+ else
41
+ raise Pry::MethodNotFound,
42
+ "'#{method.name_with_owner}' has no super method"
43
+ end
44
+ end
45
+
46
+ if !method || (!method_name && internal_binding?(context))
47
+ raise Pry::MethodNotFound,
48
+ 'no method name given, and context is not a method'
49
+ end
50
+
51
+ set_file_and_dir_locals(method.source_file)
52
+ method
53
+ end
54
+
55
+ # Remove any common leading whitespace from every line in `text`. This
56
+ # can be used to make a HEREDOC line up with the left margin, without
57
+ # sacrificing the indentation level of the source code.
58
+ #
59
+ # @example
60
+ # opt.banner(unindent(<<-USAGE))
61
+ # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
62
+ # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
63
+ # "Ut enim ad minim veniam."
64
+ # USAGE
65
+ #
66
+ # @param [String] dirty_text The text from which to remove indentation
67
+ # @return [String] the text with indentation stripped
68
+ def unindent(dirty_text, left_padding = 0)
69
+ text = dirty_text.sub(/\A[ \t]+\z/, '') # Empty blank lines.
70
+
71
+ # Find the longest common whitespace to all indented lines. Ignore lines
72
+ # containing just -- or ++ as these seem to be used by comment authors
73
+ # as delimiters.
74
+ scanned_text = text.scan(/^[ \t]*(?!--\n|\+\+\n)(?=[^ \t\n])/)
75
+ margin = scanned_text.inject do |current_margin, next_indent|
76
+ if next_indent.start_with?(current_margin)
77
+ current_margin
78
+ elsif current_margin.start_with?(next_indent)
79
+ next_indent
80
+ else
81
+ ''
82
+ end
83
+ end
84
+
85
+ text.gsub(/^#{margin}/, ' ' * left_padding)
86
+ end
87
+
88
+ # Restrict a string to the given range of lines (1-indexed)
89
+ # @param [String] content The string.
90
+ # @param [Range, Integer] lines The line(s) to restrict it to.
91
+ # @return [String] The resulting string.
92
+ def restrict_to_lines(content, lines)
93
+ line_range = one_index_range_or_number(lines)
94
+ Array(content.lines.to_a[line_range]).join
95
+ end
96
+
97
+ def one_index_number(line_number)
98
+ line_number > 0 ? line_number - 1 : line_number
99
+ end
100
+
101
+ # convert a 1-index range to a 0-indexed one
102
+ def one_index_range(range)
103
+ Range.new(one_index_number(range.begin), one_index_number(range.end))
104
+ end
105
+
106
+ def one_index_range_or_number(range_or_number)
107
+ case range_or_number
108
+ when Range
109
+ one_index_range(range_or_number)
110
+ else
111
+ one_index_number(range_or_number)
112
+ end
113
+ end
114
+
115
+ def absolute_index_number(line_number, array_length)
116
+ if line_number >= 0
117
+ line_number
118
+ else
119
+ [array_length + line_number, 0].max
120
+ end
121
+ end
122
+
123
+ def absolute_index_range(range_or_number, array_length)
124
+ case range_or_number
125
+ when Range
126
+ a = absolute_index_number(range_or_number.begin, array_length)
127
+ b = absolute_index_number(range_or_number.end, array_length)
128
+ else
129
+ a = b = absolute_index_number(range_or_number, array_length)
130
+ end
131
+
132
+ Range.new(a, b)
133
+ end
134
+
135
+ def set_file_and_dir_locals(file_name, pry = pry_instance, ctx = target)
136
+ return if !ctx || !file_name
137
+
138
+ pry.last_file = File.expand_path(file_name)
139
+ pry.inject_local("_file_", pry.last_file, ctx)
140
+
141
+ pry.last_dir = File.dirname(pry.last_file)
142
+ pry.inject_local("_dir_", pry.last_dir, ctx)
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Helpers
5
+ # This class contains methods useful for extracting
6
+ # documentation from methods and classes.
7
+ module DocumentationHelpers
8
+ YARD_TAGS = %w[
9
+ param return option yield attr attr_reader attr_writer deprecate example
10
+ raise
11
+ ].freeze
12
+
13
+ module_function
14
+
15
+ def process_rdoc(comment)
16
+ comment = comment.dup
17
+ last_match_ruby = proc do
18
+ SyntaxHighlighter.highlight(Regexp.last_match(1))
19
+ end
20
+
21
+ comment.gsub(%r{<code>(?:\s*\n)?(.*?)\s*</code>}m, &last_match_ruby)
22
+ .gsub(%r{<em>(?:\s*\n)?(.*?)\s*</em>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
23
+ .gsub(%r{<i>(?:\s*\n)?(.*?)\s*</i>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
24
+ .gsub(%r{<tt>(?:\s*\n)?(.*?)\s*</tt>}m, &last_match_ruby)
25
+ .gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{Regexp.last_match(1)}\e[0m" }
26
+ .gsub(/((?:^[ \t]+(?:(?!.+\e\[)).+(?:\n+|\Z))+)/, &last_match_ruby)
27
+ .gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{last_match_ruby.call}`" }
28
+ end
29
+
30
+ def process_yardoc_tag(comment, tag)
31
+ in_tag_block = nil
32
+ comment.lines.map do |v|
33
+ if in_tag_block && v !~ /^\S/
34
+ Pry::Helpers::Text.strip_color Pry::Helpers::Text.strip_color(v)
35
+ elsif in_tag_block
36
+ in_tag_block = false
37
+ v
38
+ else
39
+ in_tag_block = true if v =~ /^@#{tag}/
40
+ v
41
+ end
42
+ end.join
43
+ end
44
+
45
+ def process_yardoc(comment)
46
+ (YARD_TAGS - %w[example])
47
+ .inject(comment) { |a, v| process_yardoc_tag(a, v) }
48
+ .gsub(/^@(#{YARD_TAGS.join("|")})/) { "\e[33m#{Regexp.last_match(1)}\e[0m" }
49
+ end
50
+
51
+ def process_comment_markup(comment)
52
+ process_yardoc process_rdoc(comment)
53
+ end
54
+
55
+ # @param [String] code
56
+ # @return [String]
57
+ def strip_comments_from_c_code(code)
58
+ code.sub(%r{\A\s*/\*.*?\*/\s*}m, '')
59
+ end
60
+
61
+ # Given a string that makes up a comment in a source-code file parse out the content
62
+ # that the user is intended to read. (i.e. without leading indentation, #-characters
63
+ # or shebangs)
64
+ #
65
+ # @param [String] comment
66
+ # @return [String]
67
+ def get_comment_content(comment)
68
+ comment = comment.dup
69
+ # Remove #!/usr/bin/ruby
70
+ comment.gsub!(/\A\#!.*$/, '')
71
+ # Remove leading empty comment lines
72
+ comment.gsub!(/\A\#+?$/, '')
73
+ comment.gsub!(/^\s*#/, '')
74
+ strip_leading_whitespace(comment)
75
+ end
76
+
77
+ # @param [String] text
78
+ # @return [String]
79
+ def strip_leading_whitespace(text)
80
+ Pry::Helpers::CommandHelpers.unindent(text)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Helpers
5
+ module OptionsHelpers
6
+ module_function
7
+
8
+ # Add method options to the Pry::Slop instance
9
+ def method_options(opt)
10
+ @method_target = target
11
+ opt.on :M, "instance-methods", "Operate on instance methods."
12
+ opt.on :m, :methods, "Operate on methods."
13
+ opt.on :s, :super, "Select the 'super' method. Can be repeated to " \
14
+ "traverse the ancestors.", as: :count
15
+ opt.on(
16
+ :c, :context, "Select object context to run under.", argument: true
17
+ ) do |context|
18
+ @method_target = Pry.binding_for(target.eval(context))
19
+ end
20
+ end
21
+
22
+ # Get the method object parsed by the slop instance
23
+ def method_object
24
+ @method_object ||= get_method_or_raise(
25
+ args.empty? ? nil : args.join(" "),
26
+ @method_target,
27
+ super: opts[:super],
28
+ instance: opts.present?(:'instance-methods') && !opts.present?(:methods),
29
+ methods: opts.present?(:methods) && !opts.present?(:'instance-methods')
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbconfig'
4
+
5
+ class Pry
6
+ module Helpers
7
+ # Contains methods for querying the platform that Pry is running on
8
+ # @api public
9
+ # @since v0.12.0
10
+ module Platform
11
+ # @return [Boolean]
12
+ def self.mac_osx?
13
+ !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
14
+ end
15
+
16
+ # @return [Boolean]
17
+ def self.linux?
18
+ !!(RbConfig::CONFIG['host_os'] =~ /linux/i)
19
+ end
20
+
21
+ # @return [Boolean] true when Pry is running on Windows with ANSI support,
22
+ # false otherwise
23
+ def self.windows?
24
+ !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
25
+ end
26
+
27
+ # @return [Boolean]
28
+ def self.windows_ansi?
29
+ return false unless windows?
30
+
31
+ !!(defined?(Win32::Console) || Pry::Env['ANSICON'] || mri?)
32
+ end
33
+
34
+ # @return [Boolean]
35
+ def self.jruby?
36
+ RbConfig::CONFIG['ruby_install_name'] == 'jruby'
37
+ end
38
+
39
+ # @return [Boolean]
40
+ def self.jruby_19?
41
+ jruby? && RbConfig::CONFIG['ruby_version'] == '1.9'
42
+ end
43
+
44
+ # @return [Boolean]
45
+ def self.mri?
46
+ RbConfig::CONFIG['ruby_install_name'] == 'ruby'
47
+ end
48
+
49
+ # @return [Boolean]
50
+ def self.mri_2?
51
+ mri? && RUBY_VERSION.start_with?('2')
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Helpers
5
+ def self.tablify_or_one_line(heading, things, pry_instance = Pry.new)
6
+ plain_heading = Pry::Helpers::Text.strip_color(heading)
7
+ attempt = Table.new(things, column_count: things.size)
8
+ if attempt.fits_on_line?(pry_instance.output.width - plain_heading.size - 2)
9
+ "#{heading}: #{attempt}\n"
10
+ else
11
+ content = tablify_to_screen_width(things, { indent: ' ' }, pry_instance)
12
+ "#{heading}: \n#{content}\n"
13
+ end
14
+ end
15
+
16
+ def self.tablify_to_screen_width(things, options, pry_instance = Pry.new)
17
+ options ||= {}
18
+ things = things.compact
19
+ if (indent = options[:indent])
20
+ usable_width = pry_instance.output.width - indent.size
21
+ tablify(things, usable_width, pry_instance).to_s.gsub(/^/, indent)
22
+ else
23
+ tablify(things, pry_instance.output.width, pry_instance).to_s
24
+ end
25
+ end
26
+
27
+ def self.tablify(things, line_length, pry_instance = Pry.new)
28
+ table = Table.new(things, { column_count: things.size }, pry_instance)
29
+ until (table.column_count == 1) || table.fits_on_line?(line_length)
30
+ table.column_count -= 1
31
+ end
32
+ table
33
+ end
34
+
35
+ class Table
36
+ attr_reader :items, :column_count
37
+ def initialize(items, args, pry_instance = Pry.new)
38
+ @column_count = args[:column_count]
39
+ @config = pry_instance.config
40
+ self.items = items
41
+ end
42
+
43
+ def to_s
44
+ rows_to_s.join("\n")
45
+ end
46
+
47
+ def rows_to_s(style = :color_on)
48
+ widths = columns.map { |e| _max_width(e) }
49
+ @rows_without_colors.map do |r|
50
+ padded = []
51
+ r.each_with_index do |e, i|
52
+ next unless e
53
+
54
+ item = e.ljust(widths[i])
55
+ item.sub! e, _recall_color_for(e) if style == :color_on
56
+ padded << item
57
+ end
58
+ padded.join(@config.ls.separator)
59
+ end
60
+ end
61
+
62
+ def items=(items)
63
+ @items = items
64
+ _rebuild_colorless_cache
65
+ _recolumn
66
+ end
67
+
68
+ def column_count=(count)
69
+ @column_count = count
70
+ _recolumn
71
+ end
72
+
73
+ def fits_on_line?(line_length)
74
+ _max_width(rows_to_s(:no_color)) <= line_length
75
+ end
76
+
77
+ def columns
78
+ @rows_without_colors.transpose
79
+ end
80
+
81
+ def ==(other)
82
+ items == other.to_a
83
+ end
84
+
85
+ def to_a
86
+ items.to_a
87
+ end
88
+
89
+ private
90
+
91
+ def _max_width(things)
92
+ things.compact.map(&:size).max || 0
93
+ end
94
+
95
+ def _rebuild_colorless_cache
96
+ @colorless_cache = {}
97
+ @plain_items = []
98
+ items.map do |e|
99
+ plain = Pry::Helpers::Text.strip_color(e)
100
+ @colorless_cache[plain] = e
101
+ @plain_items << plain
102
+ end
103
+ end
104
+
105
+ def _recolumn
106
+ @rows_without_colors = []
107
+ return if items.size.zero?
108
+
109
+ row_count = (items.size.to_f / column_count).ceil
110
+ row_count.times do |i|
111
+ row_indices = (0...column_count).map { |e| row_count * e + i }
112
+ @rows_without_colors << row_indices.map { |e| @plain_items[e] }
113
+ end
114
+ end
115
+
116
+ def _recall_color_for(thing)
117
+ @colorless_cache[thing]
118
+ end
119
+ end
120
+ end
121
+ end