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,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # A super-class of Commands with structure.
5
+ #
6
+ # This class implements the bare-minimum functionality that a command should
7
+ # have, namely a --help switch, and then delegates actual processing to its
8
+ # subclasses.
9
+ #
10
+ # Create subclasses using {Pry::CommandSet#create_command}, and override the
11
+ # `options(opt)` method to set up an instance of Pry::Slop, and the `process`
12
+ # method to actually run the command. If necessary, you can also override
13
+ # `setup` which will be called before `options`, for example to require any
14
+ # gems your command needs to run, or to set up state.
15
+ class ClassCommand < Command
16
+ class << self
17
+ # Ensure that subclasses inherit the options, description and
18
+ # match from a ClassCommand super class.
19
+ def inherited(klass)
20
+ klass.match match
21
+ klass.description description
22
+ klass.command_options options
23
+ end
24
+
25
+ def source
26
+ source_object.source
27
+ end
28
+
29
+ def doc
30
+ new.help
31
+ end
32
+
33
+ def source_location
34
+ source_object.source_location
35
+ end
36
+
37
+ def source_file
38
+ source_object.source_file
39
+ end
40
+ alias file source_file
41
+
42
+ def source_line
43
+ source_object.source_line
44
+ end
45
+ alias line source_line
46
+
47
+ private
48
+
49
+ # The object used to extract the source for the command.
50
+ #
51
+ # This should be a `Pry::Method(block)` for a command made with `create_command`
52
+ # and a `Pry::WrappedModule(self)` for a command that's a standard class.
53
+ # @return [Pry::WrappedModule, Pry::Method]
54
+ def source_object
55
+ @source_object ||= if name =~ /^[A-Z]/
56
+ Pry::WrappedModule(self)
57
+ else
58
+ Pry::Method(block)
59
+ end
60
+ end
61
+ end
62
+
63
+ attr_accessor :opts
64
+ attr_accessor :args
65
+
66
+ # Set up `opts` and `args`, and then call `process`.
67
+ #
68
+ # This method will display help if necessary.
69
+ #
70
+ # @param [Array<String>] args The arguments passed
71
+ # @return [Object] The return value of `process` or VOID_VALUE
72
+ def call(*args)
73
+ setup
74
+
75
+ self.opts = slop
76
+ self.args = opts.parse!(args)
77
+
78
+ if opts.present?(:help)
79
+ output.puts slop.help
80
+ void
81
+ else
82
+ process(*normalize_method_args(method(:process), args))
83
+ end
84
+ end
85
+
86
+ # Return the help generated by Pry::Slop for this command.
87
+ def help
88
+ slop.help
89
+ end
90
+
91
+ # Return an instance of Pry::Slop that can parse either subcommands or the
92
+ # options that this command accepts.
93
+ def slop
94
+ Pry::Slop.new do |opt|
95
+ opt.banner(unindent(self.class.banner))
96
+ subcommands(opt)
97
+ options(opt)
98
+ opt.on :h, :help, 'Show this message.'
99
+ end
100
+ end
101
+
102
+ # Generate shell completions
103
+ # @param [String] search The line typed so far
104
+ # @return [Array<String>] the words to complete
105
+ def complete(search)
106
+ slop.flat_map do |opt|
107
+ [opt.long && "--#{opt.long} " || opt.short && "-#{opt.short}"]
108
+ end.compact + super
109
+ end
110
+
111
+ # A method called just before `options(opt)` as part of `call`.
112
+ #
113
+ # This method can be used to set up any context your command needs to run,
114
+ # for example requiring gems, or setting default values for options.
115
+ #
116
+ # @example
117
+ # def setup
118
+ # require 'gist'
119
+ # @action = :method
120
+ # end
121
+ def setup; end
122
+
123
+ # A method to setup Pry::Slop commands so it can parse the subcommands your
124
+ # command expects. If you need to set up default values, use `setup`
125
+ # instead.
126
+ #
127
+ # @example A minimal example
128
+ # def subcommands(cmd)
129
+ # cmd.command :download do |opt|
130
+ # description 'Downloads a content from a server'
131
+ #
132
+ # opt.on :verbose, 'Use verbose output'
133
+ #
134
+ # run do |options, arguments|
135
+ # ContentDownloader.download(options, arguments)
136
+ # end
137
+ # end
138
+ # end
139
+ #
140
+ # @example Define the invocation block anywhere you want
141
+ # def subcommands(cmd)
142
+ # cmd.command :download do |opt|
143
+ # description 'Downloads a content from a server'
144
+ #
145
+ # opt.on :verbose, 'Use verbose output'
146
+ # end
147
+ # end
148
+ #
149
+ # def process
150
+ # # Perform calculations...
151
+ # opts.fetch_command(:download).run do |options, arguments|
152
+ # ContentDownloader.download(options, arguments)
153
+ # end
154
+ # # More calculations...
155
+ # end
156
+ def subcommands(cmd); end
157
+
158
+ # A method to setup Pry::Slop so it can parse the options your command expects.
159
+ #
160
+ # @note Please don't do anything side-effecty in the main part of this
161
+ # method, as it may be called by Pry at any time for introspection reasons.
162
+ # If you need to set up default values, use `setup` instead.
163
+ #
164
+ # @example
165
+ # def options(opt)
166
+ # opt.banner "Gists methods or classes"
167
+ # opt.on(:c, :class, "gist a class") do
168
+ # @action = :class
169
+ # end
170
+ # end
171
+ def options(opt); end
172
+
173
+ # The actual body of your command should go here.
174
+ #
175
+ # The `opts` method can be called to get the options that Pry::Slop has passed,
176
+ # and `args` gives the remaining, unparsed arguments.
177
+ #
178
+ # The return value of this method is discarded unless the command was
179
+ # created with `:keep_retval => true`, in which case it is returned to the
180
+ # repl.
181
+ #
182
+ # @example
183
+ # def process
184
+ # if opts.present?(:class)
185
+ # gist_class
186
+ # else
187
+ # gist_method
188
+ # end
189
+ # end
190
+ def process
191
+ raise CommandError, "command '#{command_name}' not implemented"
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,211 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
5
+ class Pry
6
+ # Manage the processing of command line options
7
+ class CLI
8
+ NoOptionsError = Class.new(StandardError)
9
+
10
+ class << self
11
+ # @return [Proc] The Proc defining the valid command line options.
12
+ attr_accessor :options
13
+
14
+ # @return [Array] The Procs that process the parsed options. Plugins can
15
+ # utilize this facility in order to add and process their own Pry
16
+ # options.
17
+ attr_accessor :option_processors
18
+
19
+ # @return [Array<String>] The input array of strings to process
20
+ # as CLI options.
21
+ attr_accessor :input_args
22
+
23
+ # Add another set of CLI options (a Pry::Slop block)
24
+ def add_options(&block)
25
+ if options
26
+ old_options = options
27
+ self.options = proc do
28
+ instance_exec(&old_options)
29
+ instance_exec(&block)
30
+ end
31
+ else
32
+ self.options = block
33
+ end
34
+
35
+ self
36
+ end
37
+
38
+ # Add a block responsible for processing parsed options.
39
+ def add_option_processor(&block)
40
+ self.option_processors ||= []
41
+ option_processors << block
42
+
43
+ self
44
+ end
45
+
46
+ # Clear `options` and `option_processors`
47
+ def reset
48
+ self.options = nil
49
+ self.option_processors = nil
50
+ end
51
+
52
+ def parse_options(args = ARGV)
53
+ unless options
54
+ raise NoOptionsError,
55
+ "No command line options defined! Use Pry::CLI.add_options to " \
56
+ "add command line options."
57
+ end
58
+
59
+ @pass_argv = args.index { |cli_arg| %w[- --].include?(cli_arg) }
60
+ if @pass_argv
61
+ slop_args = args[0...@pass_argv]
62
+ self.input_args = args.replace(args[@pass_argv + 1..-1])
63
+ else
64
+ self.input_args = slop_args = args
65
+ end
66
+
67
+ begin
68
+ opts = Pry::Slop.parse!(
69
+ slop_args,
70
+ help: true,
71
+ multiple_switches: false,
72
+ strict: true,
73
+ &options
74
+ )
75
+ rescue Pry::Slop::InvalidOptionError
76
+ # Display help message on unknown switches and exit.
77
+ puts Pry::Slop.new(&options)
78
+ Kernel.exit
79
+ end
80
+
81
+ Pry.initial_session_setup
82
+ Pry.final_session_setup
83
+
84
+ # Option processors are optional.
85
+ option_processors.each { |processor| processor.call(opts) } if option_processors
86
+
87
+ opts
88
+ end
89
+
90
+ def start(opts)
91
+ Kernel.exit if opts.help?
92
+
93
+ # invoked via cli
94
+ Pry.cli = true
95
+
96
+ # create the actual context
97
+ if opts[:context]
98
+ Pry.initial_session_setup
99
+ context = Pry.binding_for(eval(opts[:context])) # rubocop:disable Security/Eval
100
+ Pry.final_session_setup
101
+ else
102
+ context = Pry.toplevel_binding
103
+ end
104
+
105
+ if !@pass_argv && Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
106
+ full_name = File.expand_path(Pry::CLI.input_args.first)
107
+ Pry.load_file_through_repl(full_name)
108
+ Kernel.exit
109
+ end
110
+
111
+ # Start the session (running any code passed with -e, if there is any)
112
+ Pry.start(context, input: StringIO.new(Pry.config.exec_string))
113
+ end
114
+ end
115
+
116
+ reset
117
+ end
118
+ end
119
+
120
+ # The default Pry command line options (before plugin options are included)
121
+ Pry::CLI.add_options do
122
+ banner(
123
+ "Usage: pry [OPTIONS]\n" \
124
+ "Start a Pry session.\n" \
125
+ "See http://pry.github.io/ for more information.\n" \
126
+ "Copyright (c) 2010 John Mair (banisterfiend)" \
127
+ )
128
+
129
+ on(
130
+ :e, :exec=, "A line of code to execute in context before the session starts"
131
+ ) do |input|
132
+ Pry.config.exec_string += "\n" unless Pry.config.exec_string.empty?
133
+ Pry.config.exec_string += input
134
+ end
135
+
136
+ on "no-pager", "Disable pager for long output" do
137
+ Pry.config.pager = false
138
+ end
139
+
140
+ on "no-history", "Disable history loading" do
141
+ Pry.config.history_load = false
142
+ end
143
+
144
+ on "no-color", "Disable syntax highlighting for session" do
145
+ Pry.config.color = false
146
+ end
147
+
148
+ on "no-multiline", "Disables multiline (defaults to true with Reline)" do
149
+ Pry.config.multiline = false
150
+ end
151
+
152
+ on :f, "Suppress loading of pryrc" do
153
+ Pry.config.should_load_rc = false
154
+ Pry.config.should_load_local_rc = false
155
+ end
156
+
157
+ on :s, "select-plugin=", "Only load specified plugin (and no others)." do |_plugin_name|
158
+ warn "The --select-plugin option is deprecated and has no effect"
159
+ end
160
+
161
+ on :d, "disable-plugin=", "Disable a specific plugin." do |_plugin_name|
162
+ warn "The --disable-plugin option is deprecated and has no effect"
163
+ end
164
+
165
+ on "no-plugins", "Suppress loading of plugins." do
166
+ warn "The --no-plugins option is deprecated and has no effect"
167
+ end
168
+
169
+ on "plugins", "List installed plugins." do
170
+ warn "The --plugins option is deprecated and has no effect"
171
+ warn "Try using `gem list pry-`"
172
+ Kernel.exit
173
+ end
174
+
175
+ on "simple-prompt", "Enable simple prompt mode" do
176
+ Pry.config.prompt = Pry::Prompt[:simple]
177
+ end
178
+
179
+ on "noprompt", "No prompt mode" do
180
+ Pry.config.prompt = Pry::Prompt[:none]
181
+ end
182
+
183
+ on :r, :require=, "`require` a Ruby script at startup" do |file|
184
+ Pry.config.requires << file
185
+ end
186
+
187
+ on(:I=, "Add a path to the $LOAD_PATH", as: Array, delimiter: ":") do |load_path|
188
+ load_path.map! do |path|
189
+ %r{\A\./} =~ path ? path : File.expand_path(path)
190
+ end
191
+
192
+ $LOAD_PATH.unshift(*load_path)
193
+ end
194
+
195
+ on "gem", "Shorthand for -I./lib -rgemname" do |_load_path|
196
+ $LOAD_PATH.unshift("./lib")
197
+ Dir["./lib/*.rb"].each do |file|
198
+ Pry.config.requires << file
199
+ end
200
+ end
201
+
202
+ on :v, :version, "Display the Pry version" do
203
+ puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
204
+ Kernel.exit
205
+ end
206
+
207
+ on :c, :context=,
208
+ "Start the session in the specified context. Equivalent to " \
209
+ "`context.pry` in a session.",
210
+ default: "Pry.toplevel_binding"
211
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'method_source'
4
+
5
+ class Pry
6
+ class CodeFile
7
+ DEFAULT_EXT = '.rb'.freeze
8
+
9
+ # List of all supported languages.
10
+ # @return [Hash]
11
+ EXTENSIONS = {
12
+ %w[.py] => :python,
13
+ %w[.js] => :javascript,
14
+ %w[.css] => :css,
15
+ %w[.xml] => :xml,
16
+ %w[.php] => :php,
17
+ %w[.html] => :html,
18
+ %w[.diff] => :diff,
19
+ %w[.java] => :java,
20
+ %w[.json] => :json,
21
+ %w[.c .h] => :c,
22
+ %w[.rhtml] => :rhtml,
23
+ %w[.yaml .yml] => :yaml,
24
+ %w[.cpp .hpp .cc .h .cxx] => :cpp,
25
+ %w[.rb .ru .irbrc .gemspec .pryrc .rake] => :ruby
26
+ }.freeze
27
+
28
+ FILES = {
29
+ %w[Gemfile Rakefile Guardfile Capfile] => :ruby
30
+ }.freeze
31
+
32
+ # Store the current working directory. This allows show-source etc. to work if
33
+ # your process has changed directory since boot. [Issue #675]
34
+ INITIAL_PWD = Dir.pwd
35
+
36
+ # @return [Symbol] The type of code stored in this wrapper.
37
+ attr_reader :code_type
38
+
39
+ # @param [String] filename The name of a file with code to be detected
40
+ # @param [Symbol] code_type The type of code the `filename` contains
41
+ def initialize(filename, code_type = type_from_filename(filename))
42
+ @filename = filename
43
+ @code_type = code_type
44
+ end
45
+
46
+ # @return [String] The code contained in the current `@filename`.
47
+ def code
48
+ if @filename == Pry.eval_path
49
+ Pry.line_buffer.drop(1)
50
+ elsif Pry::Method::Patcher.code_for(@filename)
51
+ Pry::Method::Patcher.code_for(@filename)
52
+ else
53
+ path = abs_path
54
+ @code_type = type_from_filename(path)
55
+ File.read(path)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ # @raise [MethodSource::SourceNotFoundError] if the `filename` is not
62
+ # readable for some reason.
63
+ # @return [String] absolute path for the given `filename`.
64
+ def abs_path
65
+ code_path.detect { |path| readable?(path) } ||
66
+ raise(MethodSource::SourceNotFoundError,
67
+ "Cannot open #{@filename.inspect} for reading.")
68
+ end
69
+
70
+ # @param [String] path
71
+ # @return [Boolean] if the path, with or without the default ext,
72
+ # is a readable file then `true`, otherwise `false`.
73
+ def readable?(path)
74
+ File.readable?(path) && !File.directory?(path) ||
75
+ File.readable?(path << DEFAULT_EXT)
76
+ end
77
+
78
+ # @return [Array] All the paths that contain code that Pry can use for its
79
+ # API's. Skips directories.
80
+ def code_path
81
+ [from_pwd, from_pry_init_pwd, *from_load_path]
82
+ end
83
+
84
+ # @param [String] filename
85
+ # @param [Symbol] default (:unknown) the file type to assume if none could be
86
+ # detected.
87
+ # @return [Symbol, nil] The SyntaxHighlighter type of a file from its
88
+ # extension, or `nil` if `:unknown`.
89
+ def type_from_filename(filename, default = :unknown)
90
+ _, @code_type = EXTENSIONS.find do |k, _|
91
+ k.any? { |ext| ext == File.extname(filename) }
92
+ end || FILES.find do |k, _|
93
+ k.any? { |file_name| file_name == File.basename(filename) }
94
+ end
95
+
96
+ code_type || default
97
+ end
98
+
99
+ # @return [String]
100
+ def from_pwd
101
+ File.expand_path(@filename, Dir.pwd)
102
+ end
103
+
104
+ # @return [String]
105
+ def from_pry_init_pwd
106
+ File.expand_path(@filename, INITIAL_PWD)
107
+ end
108
+
109
+ # @return [String]
110
+ def from_load_path
111
+ $LOAD_PATH.map { |path| File.expand_path(@filename, path) }
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Code
5
+ # Represents a range of lines in a code listing.
6
+ #
7
+ # @api private
8
+ class CodeRange
9
+ # @param [Integer] start_line
10
+ # @param [Integer?] end_line
11
+ def initialize(start_line, end_line = nil)
12
+ @start_line = start_line
13
+ @end_line = end_line
14
+ force_set_end_line
15
+ end
16
+
17
+ # @param [Array<LOC>] lines
18
+ # @return [Range]
19
+ def indices_range(lines)
20
+ Range.new(*indices(lines))
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :start_line
26
+
27
+ attr_reader :end_line
28
+
29
+ # If `end_line` is equal to `nil`, then calculate it from the first
30
+ # parameter, `start_line`. Otherwise, leave it as it is.
31
+ # @return [void]
32
+ def force_set_end_line
33
+ if start_line.is_a?(Range)
34
+ set_end_line_from_range
35
+ else
36
+ @end_line ||= start_line
37
+ end
38
+ end
39
+
40
+ # Finds indices of `start_line` and `end_line` in the given Array of
41
+ # +lines+.
42
+ #
43
+ # @param [Array<LOC>] lines
44
+ # @return [Array<Integer>]
45
+ def indices(lines)
46
+ [find_start_index(lines), find_end_index(lines)]
47
+ end
48
+
49
+ # @return [Integer]
50
+ def find_start_index(lines)
51
+ return start_line if start_line < 0
52
+
53
+ lines.index { |loc| loc.lineno >= start_line } || lines.length
54
+ end
55
+
56
+ # @return [Integer]
57
+ def find_end_index(lines)
58
+ return end_line if end_line < 0
59
+
60
+ (lines.index { |loc| loc.lineno > end_line } || 0) - 1
61
+ end
62
+
63
+ # For example, if the range is 4..10, then `start_line` would be equal to
64
+ # 4 and `end_line` to 10.
65
+ # @return [void]
66
+ def set_end_line_from_range
67
+ @end_line = start_line.last
68
+ @end_line -= 1 if start_line.exclude_end?
69
+ @start_line = start_line.first
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Code
5
+ # Represents a line of code (which may, in fact, contain multiple lines if
6
+ # the entirety was eval'd as a single unit following the `edit` command).
7
+ #
8
+ # A line of code is a tuple, which consists of a line and a line number. A
9
+ # `LOC` object's state (namely, the line parameter) can be changed via
10
+ # instance methods. `Pry::Code` heavily uses this class.
11
+ #
12
+ # @api private
13
+ # @example
14
+ # loc = LOC.new("def example\n :example\nend", 1)
15
+ # puts loc.line
16
+ # def example
17
+ # :example
18
+ # end
19
+ # #=> nil
20
+ #
21
+ # loc.indent(3)
22
+ # loc.line #=> " def example\n :example\nend"
23
+ class LOC
24
+ # @return [Array<String, Integer>]
25
+ attr_reader :tuple
26
+
27
+ # @param [String] line The line of code.
28
+ # @param [Integer] lineno The position of the +line+.
29
+ def initialize(line, lineno)
30
+ @tuple = [line.chomp, lineno.to_i]
31
+ end
32
+
33
+ # @return [Boolean]
34
+ def ==(other)
35
+ other.tuple == tuple
36
+ end
37
+
38
+ def dup
39
+ self.class.new(line, lineno)
40
+ end
41
+
42
+ # @return [String]
43
+ def line
44
+ tuple.first
45
+ end
46
+
47
+ # @return [Integer]
48
+ def lineno
49
+ tuple.last
50
+ end
51
+
52
+ # Paints the `line` of code.
53
+ #
54
+ # @param [Symbol] code_type
55
+ # @return [void]
56
+ def colorize(code_type)
57
+ tuple[0] = SyntaxHighlighter.highlight(line, code_type)
58
+ end
59
+
60
+ # Prepends the line number `lineno` to the `line`.
61
+ #
62
+ # @param [Integer] max_width
63
+ # @return [void]
64
+ def add_line_number(max_width = 0, color = false)
65
+ padded = lineno.to_s.rjust(max_width)
66
+ colorized_lineno =
67
+ if color
68
+ Pry::Helpers::BaseHelpers.colorize_code(padded)
69
+ else
70
+ padded
71
+ end
72
+ properly_padded_line = handle_multiline_entries_from_edit_command(line, max_width)
73
+ tuple[0] = "#{colorized_lineno}: #{properly_padded_line}"
74
+ end
75
+
76
+ # Prepends a marker "=>" or an empty marker to the +line+.
77
+ #
78
+ # @param [Integer] marker_lineno If it is equal to the `lineno`, then
79
+ # prepend a hashrocket. Otherwise, an empty marker.
80
+ # @return [void]
81
+ def add_marker(marker_lineno)
82
+ tuple[0] =
83
+ if lineno == marker_lineno
84
+ " => #{line}"
85
+ else
86
+ " #{line}"
87
+ end
88
+ end
89
+
90
+ # Indents the `line` with +distance+ spaces.
91
+ #
92
+ # @param [Integer] distance
93
+ # @return [void]
94
+ def indent(distance)
95
+ tuple[0] = "#{' ' * distance}#{line}"
96
+ end
97
+
98
+ def handle_multiline_entries_from_edit_command(line, max_width)
99
+ line.split("\n").map.with_index do |inner_line, i|
100
+ i.zero? ? inner_line : "#{' ' * (max_width + 2)}#{inner_line}"
101
+ end.join("\n")
102
+ end
103
+ end
104
+ end
105
+ end