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,321 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # @api private
5
+ class Config
6
+ extend Attributable
7
+
8
+ # @return [IO, #readline] the object from which Pry retrieves its lines of
9
+ # input
10
+ attribute :input
11
+
12
+ # @return [IO, #puts] where Pry should output results provided by {input}
13
+ attribute :output
14
+
15
+ # @return [Pry::CommandSet]
16
+ attribute :commands
17
+
18
+ # @return [Proc] the printer for Ruby expressions (not commands)
19
+ attribute :print
20
+
21
+ # @return [Proc] the printer for exceptions
22
+ attribute :exception_handler
23
+
24
+ # @return [Array] Exception that Pry shouldn't rescue
25
+ attribute :unrescued_exceptions
26
+
27
+ # @return [Integer] The number of lines of context to show before and after
28
+ # exceptions
29
+ attribute :default_window_size
30
+
31
+ # @return [Pry::Hooks]
32
+ attribute :hooks
33
+
34
+ # @return [Pry::Prompt]
35
+ attribute :prompt
36
+
37
+ # @return [String] The display name that is part of the prompt
38
+ attribute :prompt_name
39
+
40
+ # @return [Array<Object>] the list of objects that are known to have a
41
+ # 1-line #inspect output suitable for prompt
42
+ attribute :prompt_safe_contexts
43
+
44
+ # If it is a String, then that String is used as the shell
45
+ # command to invoke the editor.
46
+ #
47
+ # If it responds to #call is callable then `file`, `line`, and `reloading`
48
+ # are passed to it. `reloading` indicates whether Pry will be reloading code
49
+ # after the shell command returns. All parameters are optional.
50
+ # @return [String, #call]
51
+ attribute :editor
52
+
53
+ # A string that must precede all commands. For example, if is is
54
+ # set to "%", the "cd" command must be invoked as "%cd").
55
+ # @return [String]
56
+ attribute :command_prefix
57
+
58
+ # @return [Boolean]
59
+ attribute :color
60
+
61
+ # @return [Boolean]
62
+ attribute :pager
63
+
64
+ # @return [Boolean]
65
+ attribute :multiline
66
+
67
+ # @return [Boolean] whether the global ~/.pryrc should be loaded
68
+ attribute :should_load_rc
69
+
70
+ # @return [Boolean] whether the local ./.pryrc should be loaded
71
+ attribute :should_load_local_rc
72
+
73
+ # @return [Boolean] whether to load files specified with the -r flag
74
+ attribute :should_load_requires
75
+
76
+ # @return [Boolean] whether to disable edit-method's auto-reloading behavior
77
+ attribute :disable_auto_reload
78
+
79
+ # Whether Pry should trap SIGINT and cause it to raise an Interrupt
80
+ # exception. This is only useful on JRuby, MRI does this for us.
81
+ # @return [Boolean]
82
+ attribute :should_trap_interrupts
83
+
84
+ # @return [Pry::History]
85
+ attribute :history
86
+
87
+ # @return [Boolean]
88
+ attribute :history_save
89
+
90
+ # @return [Boolean]
91
+ attribute :history_load
92
+
93
+ # @return [String]
94
+ attribute :history_file
95
+
96
+ # @return [Array<String,Regexp>]
97
+ attribute :history_ignorelist
98
+
99
+ # @return [Array<String>] Ruby files to be required
100
+ attribute :requires
101
+
102
+ # @return [Integer] how many input/output lines to keep in memory
103
+ attribute :memory_size
104
+
105
+ # @return [Proc] The proc that runs system commands
106
+ attribute :system
107
+
108
+ # @return [Boolean]
109
+ attribute :auto_indent
110
+
111
+ # @return [Boolean]
112
+ attribute :correct_indent
113
+
114
+ # @return [Boolean] whether or not display a warning when a command name
115
+ # collides with a method/local in the current context.
116
+ attribute :collision_warning
117
+
118
+ # @return [Hash{Symbol=>Proc}]
119
+ attribute :extra_sticky_locals
120
+
121
+ # @return [#build_completion_proc] a completer to use
122
+ attribute :completer
123
+
124
+ # @return [Boolean] suppresses whereami output on `binding.pry`
125
+ attribute :quiet
126
+
127
+ # @return [Boolean] displays a warning about experience improvement on
128
+ # Windows
129
+ attribute :windows_console_warning
130
+
131
+ # @return [Proc]
132
+ attribute :command_completions
133
+
134
+ # @return [Proc]
135
+ attribute :file_completions
136
+
137
+ # @return [Hash]
138
+ attribute :ls
139
+
140
+ # @return [String] a line of code to execute in context before the session
141
+ # starts
142
+ attribute :exec_string
143
+
144
+ # @return [String]
145
+ attribute :output_prefix
146
+
147
+ # @return [String]
148
+ # @since v0.13.0
149
+ attribute :rc_file
150
+
151
+ def initialize
152
+ merge!(
153
+ input: MemoizedValue.new { choose_input },
154
+ output: $stdout.tap { |out| out.sync = true },
155
+ commands: Pry::Commands,
156
+ prompt_name: 'pry',
157
+ prompt: Pry::Prompt[:default],
158
+ prompt_safe_contexts: [String, Numeric, Symbol, nil, true, false],
159
+ print: Pry::ColorPrinter.method(:default),
160
+ quiet: false,
161
+ exception_handler: Pry::ExceptionHandler.method(:handle_exception),
162
+
163
+ unrescued_exceptions: [
164
+ ::SystemExit, ::SignalException, Pry::TooSafeException
165
+ ],
166
+
167
+ hooks: Pry::Hooks.default,
168
+ pager: true,
169
+ system: Pry::SystemCommandHandler.method(:default),
170
+ multiline: true,
171
+ color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
172
+ default_window_size: 5,
173
+ editor: Pry::Editor.default,
174
+ rc_file: default_rc_file,
175
+ should_load_rc: true,
176
+ should_load_local_rc: true,
177
+ should_trap_interrupts: Pry::Helpers::Platform.jruby?,
178
+ disable_auto_reload: false,
179
+ command_prefix: '',
180
+ auto_indent: Pry::Helpers::BaseHelpers.use_ansi_codes?,
181
+ correct_indent: true,
182
+ collision_warning: false,
183
+ output_prefix: '=> ',
184
+ requires: [],
185
+ should_load_requires: true,
186
+ windows_console_warning: true,
187
+ control_d_handler: Pry::ControlDHandler.method(:default),
188
+ memory_size: 100,
189
+ extra_sticky_locals: {},
190
+ command_completions: proc { commands.keys },
191
+ file_completions: proc { Dir['.'] },
192
+ ls: Pry::Command::Ls::Config.default,
193
+ completer: Pry::InputCompleter,
194
+ history_save: true,
195
+ history_load: true,
196
+ history_file: Pry::History.default_file,
197
+ history_ignorelist: [],
198
+ history: MemoizedValue.new do
199
+ if defined?(input::HISTORY)
200
+ Pry::History.new(history: input::HISTORY)
201
+ else
202
+ Pry::History.new
203
+ end
204
+ end,
205
+ exec_string: ''
206
+ )
207
+
208
+ @custom_attrs = {}
209
+ end
210
+
211
+ def merge!(config_hash)
212
+ config_hash.each_pair { |attr, value| __send__("#{attr}=", value) }
213
+ self
214
+ end
215
+
216
+ def merge(config_hash)
217
+ dup.merge!(config_hash)
218
+ end
219
+
220
+ def []=(attr, value)
221
+ @custom_attrs[attr.to_s] = Config::Value.new(value)
222
+ end
223
+
224
+ def [](attr)
225
+ @custom_attrs[attr.to_s].call
226
+ end
227
+
228
+ # rubocop:disable Style/MethodMissingSuper
229
+ def method_missing(method_name, *args, &_block)
230
+ name = method_name.to_s
231
+
232
+ if name.end_with?('=')
233
+ self[name[0..-2]] = args.first
234
+ elsif @custom_attrs.key?(name)
235
+ self[name]
236
+ end
237
+ end
238
+ # rubocop:enable Style/MethodMissingSuper
239
+
240
+ def respond_to_missing?(method_name, include_all = false)
241
+ @custom_attrs.key?(method_name.to_s.tr('=', '')) || super
242
+ end
243
+
244
+ def initialize_dup(other)
245
+ super
246
+ @custom_attrs = @custom_attrs.dup
247
+ end
248
+
249
+ attr_reader :control_d_handler
250
+ def control_d_handler=(value)
251
+ proxy_proc =
252
+ if value.arity == 2
253
+ Pry::Warning.warn(
254
+ "control_d_handler's arity of 2 parameters was deprecated " \
255
+ '(eval_string, pry_instance). Now it gets passed just 1 ' \
256
+ 'parameter (pry_instance)'
257
+ )
258
+ proc do |*args|
259
+ if args.size == 2
260
+ value.call(args.first, args[1])
261
+ else
262
+ value.call(args.first.eval_string, args.first)
263
+ end
264
+ end
265
+ else
266
+ proc do |*args|
267
+ if args.size == 2
268
+ value.call(args[1])
269
+ else
270
+ value.call(args.first)
271
+ end
272
+ end
273
+ end
274
+ @control_d_handler = proxy_proc
275
+ end
276
+
277
+ private
278
+
279
+ def choose_input
280
+ input = load_readline
281
+
282
+ if Pry::Env['TERM'] == 'dumb' && (defined?(Reline) && input == Reline)
283
+ input = Pry::Input::SimpleStdio
284
+ end
285
+
286
+ input
287
+ end
288
+
289
+ def load_readline
290
+ require 'readline'
291
+ ::Readline
292
+ rescue LoadError
293
+ begin
294
+ require 'reline'
295
+ ::Reline
296
+ rescue LoadError
297
+ output.puts(
298
+ "Sorry, you can't use Pry without Readline or a compatible library. \n" \
299
+ "Possible solutions: \n" \
300
+ " * Rebuild Ruby with Readline support using `--with-readline` \n" \
301
+ " * Use the reline gem \n" \
302
+ " * Use the readline-ext gem \n " \
303
+ " * Use the rb-readline gem, which is a pure-Ruby port of Readline \n" \
304
+ " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
305
+ )
306
+ raise
307
+ end
308
+ end
309
+
310
+ def default_rc_file
311
+ [Pry::Env['PRYRC'],
312
+ # See XDG Base Directory Specification at
313
+ # https://specifications.freedesktop.org/basedir-spec/latest/
314
+ "#{Pry::Env['XDG_CONFIG_HOME']}/pry/pryrc",
315
+ File.expand_path('~/.pryrc'),
316
+ File.expand_path('~/.config/pry/pryrc')]
317
+ .compact
318
+ .find { |file| File.exist?(file) }
319
+ end
320
+ end
321
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # @api private
5
+ # @since v0.13.0
6
+ module ControlDHandler
7
+ # Deal with the ^D key being pressed. Different behaviour in different
8
+ # cases:
9
+ # 1. In an expression behave like `!` command.
10
+ # 2. At top-level session behave like `exit` command.
11
+ # 3. In a nested session behave like `cd ..`.
12
+ def self.default(pry_instance)
13
+ if !pry_instance.eval_string.empty?
14
+ # Clear input buffer.
15
+ pry_instance.eval_string = ''
16
+ elsif pry_instance.binding_stack.one?
17
+ pry_instance.binding_stack.clear
18
+ throw(:breakout)
19
+ else
20
+ # Otherwise, saves current binding stack as old stack and pops last
21
+ # binding out of binding stack (the old stack still has that binding).
22
+ cd_state = Pry::CommandState.default.state_for(Pry::Command::Cd)
23
+ cd_state.old_stack = pry_instance.binding_stack.dup
24
+ pry_instance.binding_stack.pop
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # @return [Array] Code of the method used when implementing Pry's
5
+ # __binding__, along with line indication to be used with instance_eval (and
6
+ # friends).
7
+ #
8
+ # @see Object#__binding__
9
+ BINDING_METHOD_IMPL = [<<-METHOD, __FILE__, __LINE__ + 1].freeze
10
+ # Get a binding with 'self' set to self, and no locals.
11
+ #
12
+ # The default definee is determined by the context in which the
13
+ # definition is eval'd.
14
+ #
15
+ # Please don't call this method directly, see {__binding__}.
16
+ #
17
+ # @return [Binding]
18
+ def __pry__
19
+ binding
20
+ end
21
+ METHOD
22
+ end
23
+
24
+ class Object
25
+ # Start a Pry REPL on self.
26
+ #
27
+ # If `self` is a Binding then that will be used to evaluate expressions;
28
+ # otherwise a new binding will be created.
29
+ #
30
+ # @param [Object] object the object or binding to pry
31
+ # (__deprecated__, use `object.pry`)
32
+ # @param [Hash] hash the options hash
33
+ # @example With a binding
34
+ # binding.pry
35
+ # @example On any object
36
+ # "dummy".pry
37
+ # @example With options
38
+ # def my_method
39
+ # binding.pry :quiet => true
40
+ # end
41
+ # my_method()
42
+ # @see Pry.start
43
+ def pry(object = nil, hash = {})
44
+ if object.nil? || Hash === object # rubocop:disable Style/CaseEquality
45
+ Pry.start(self, object || {})
46
+ else
47
+ Pry.start(object, hash)
48
+ end
49
+ end
50
+
51
+ # Return a binding object for the receiver.
52
+ #
53
+ # The `self` of the binding is set to the current object, and it contains no
54
+ # local variables.
55
+ #
56
+ # The default definee (http://yugui.jp/articles/846) is set such that:
57
+ #
58
+ # * If `self` is a class or module, then new methods created in the binding
59
+ # will be defined in that class or module (as in `class Foo; end`).
60
+ # * If `self` is a normal object, then new methods created in the binding will
61
+ # be defined on its singleton class (as in `class << self; end`).
62
+ # * If `self` doesn't have a real singleton class (i.e. it is a Fixnum, Float,
63
+ # Symbol, nil, true, or false), then new methods will be created on the
64
+ # object's class (as in `self.class.class_eval{ }`)
65
+ #
66
+ # Newly created constants, including classes and modules, will also be added
67
+ # to the default definee.
68
+ #
69
+ # @return [Binding]
70
+ def __binding__
71
+ # If you ever feel like changing this method, be careful about variables
72
+ # that you use. They shouldn't be inserted into the binding that will
73
+ # eventually be returned.
74
+
75
+ # When you're cd'd into a class, methods you define should be added to it.
76
+ if is_a?(Module)
77
+ # A special case, for JRuby.
78
+ # Module.new.class_eval("binding") has different behaviour than CRuby,
79
+ # where this is not needed: class_eval("binding") vs class_eval{binding}.
80
+ # Using a block works around the difference of behaviour on JRuby.
81
+ # The scope is clear of local variables. Don't add any.
82
+ #
83
+ # This fixes the following two spec failures, at https://travis-ci.org/pry/pry/jobs/274470002
84
+ # 1) ./spec/pry_spec.rb:360:in `block in (root)'
85
+ # 2) ./spec/pry_spec.rb:366:in `block in (root)'
86
+ return class_eval { binding } if Pry::Helpers::Platform.jruby? && name.nil?
87
+
88
+ # class_eval sets both self and the default definee to this class.
89
+ return class_eval("binding", __FILE__, __LINE__)
90
+ end
91
+
92
+ unless self.class.method_defined?(:__pry__)
93
+ # The easiest way to check whether an object has a working singleton class
94
+ # is to try and define a method on it. (just checking for the presence of
95
+ # the singleton class gives false positives for `true` and `false`).
96
+ # __pry__ is just the closest method we have to hand, and using
97
+ # it has the nice property that we can memoize this check.
98
+ begin
99
+ # instance_eval sets the default definee to the object's singleton class
100
+ instance_eval(*Pry::BINDING_METHOD_IMPL)
101
+
102
+ # If we can't define methods on the Object's singleton_class. Then we fall
103
+ # back to setting the default definee to be the Object's class. That seems
104
+ # nicer than having a REPL in which you can't define methods.
105
+ rescue TypeError, Pry::FrozenObjectException
106
+ # class_eval sets the default definee to self.class
107
+ self.class.class_eval(*Pry::BINDING_METHOD_IMPL)
108
+ end
109
+ end
110
+
111
+ __pry__
112
+ end
113
+ end
114
+
115
+ class BasicObject
116
+ # Return a binding object for the receiver.
117
+ #
118
+ # The `self` of the binding is set to the current object, and it contains no
119
+ # local variables.
120
+ #
121
+ # The default definee (http://yugui.jp/articles/846) is set such that new
122
+ # methods defined will be added to the singleton class of the BasicObject.
123
+ #
124
+ # @return [Binding]
125
+ def __binding__
126
+ # BasicObjects don't have respond_to?, so we just define the method
127
+ # every time. As they also don't have `.freeze`, this call won't
128
+ # fail as it can for normal Objects.
129
+ (class << self; self; end).class_eval(<<-METHOD, __FILE__, __LINE__ + 1)
130
+ # Get a binding with 'self' set to self, and no locals.
131
+ #
132
+ # The default definee is determined by the context in which the
133
+ # definition is eval'd.
134
+ #
135
+ # Please don't call this method directly, see {__binding__}.
136
+ #
137
+ # @return [Binding]
138
+ def __pry__
139
+ ::Kernel.binding
140
+ end
141
+ METHOD
142
+ __pry__
143
+ end
144
+ end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shellwords'
4
+
5
+ class Pry
6
+ class Editor
7
+ def self.default
8
+ if (visual = Pry::Env['VISUAL'])
9
+ return visual
10
+ end
11
+
12
+ if (editor = Pry::Env['EDITOR'])
13
+ return editor
14
+ end
15
+
16
+ return 'notepad' if Helpers::Platform.windows?
17
+
18
+ %w[editor nano vi].find do |editor_exe|
19
+ Kernel.system("which #{editor_exe} > /dev/null 2>&1")
20
+ end
21
+ end
22
+
23
+ include Pry::Helpers::CommandHelpers
24
+
25
+ attr_reader :pry_instance
26
+
27
+ def initialize(pry_instance)
28
+ @pry_instance = pry_instance
29
+ end
30
+
31
+ def edit_tempfile_with_content(initial_content, line = 1)
32
+ temp_file do |f|
33
+ f.puts(initial_content)
34
+ f.flush
35
+ f.close(false)
36
+ invoke_editor(f.path, line, true)
37
+ File.read(f.path)
38
+ end
39
+ end
40
+
41
+ def invoke_editor(file, line, blocking = true)
42
+ unless pry_instance.config.editor
43
+ raise CommandError,
44
+ "Please set Pry.config.editor or export $VISUAL or $EDITOR"
45
+ end
46
+
47
+ editor_invocation = build_editor_invocation_string(file, line, blocking)
48
+ return nil unless editor_invocation
49
+
50
+ if Helpers::Platform.jruby?
51
+ open_editor_on_jruby(editor_invocation)
52
+ else
53
+ open_editor(editor_invocation)
54
+ end
55
+ end
56
+
57
+ # Generate the string that's used to start the editor. This includes
58
+ # all the flags we want as well as the file and line number we
59
+ # want to open at.
60
+ def build_editor_invocation_string(file, line, blocking)
61
+ if pry_instance.config.editor.respond_to?(:call)
62
+ args = [file, line, blocking][0...(pry_instance.config.editor.arity)]
63
+ pry_instance.config.editor.call(*args)
64
+ else
65
+ sanitized_file = Helpers::Platform.windows? ? file : Shellwords.escape(file)
66
+ editor = pry_instance.config.editor
67
+ flag = blocking_flag_for_editor(blocking)
68
+ start_line = start_line_syntax_for_editor(sanitized_file, line)
69
+ "#{editor} #{flag} #{start_line}"
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ # Start the editor running, using the calculated invocation string
76
+ def open_editor(editor_invocation)
77
+ # Note we dont want to use Pry.config.system here as that
78
+ # may be invoked non-interactively (i.e via Open4), whereas we want to
79
+ # ensure the editor is always interactive
80
+ system(*Shellwords.split(editor_invocation)) ||
81
+ raise(
82
+ CommandError,
83
+ "`#{editor_invocation}` gave exit status: #{$CHILD_STATUS.exitstatus}"
84
+ )
85
+ end
86
+
87
+ # We need JRuby specific code here cos just shelling out using
88
+ # system() appears to be pretty broken :/
89
+ def open_editor_on_jruby(editor_invocation)
90
+ require 'spoon'
91
+ pid = Spoon.spawnp(*Shellwords.split(editor_invocation))
92
+ Process.waitpid(pid)
93
+ rescue FFI::NotFoundError
94
+ system(editor_invocation)
95
+ end
96
+
97
+ # Some editors that run outside the terminal allow you to control whether or
98
+ # not to block the process from which they were launched (in this case, Pry).
99
+ # For those editors, return the flag that produces the desired behavior.
100
+ def blocking_flag_for_editor(blocking)
101
+ case editor_name
102
+ when /^emacsclient/
103
+ '--no-wait' unless blocking
104
+ when /^[gm]vim/
105
+ '--nofork' if blocking
106
+ when /^jedit/
107
+ '-wait' if blocking
108
+ when /^mate/, /^subl/, /^redcar/, /^code/
109
+ '-w' if blocking
110
+ end
111
+ end
112
+
113
+ # Return the syntax for a given editor for starting the editor
114
+ # and moving to a particular line within that file
115
+ def start_line_syntax_for_editor(file_name, line_number)
116
+ # special case for 1st line
117
+ return file_name if line_number <= 1
118
+
119
+ case editor_name
120
+ when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
121
+ "+#{line_number} #{file_name}"
122
+ when /^mate/, /^geany/
123
+ "-l #{line_number} #{file_name}"
124
+ when /^code/
125
+ "-g #{file_name}:#{line_number}"
126
+ when /^subl/
127
+ "#{file_name}:#{line_number}"
128
+ when /^uedit32/
129
+ "#{file_name}/#{line_number}"
130
+ when /^jedit/
131
+ "#{file_name} +line:#{line_number}"
132
+ when /^redcar/
133
+ "-l#{line_number} #{file_name}"
134
+ else
135
+ if Helpers::Platform.windows?
136
+ file_name.to_s
137
+ else
138
+ "+#{line_number} #{file_name}"
139
+ end
140
+ end
141
+ end
142
+
143
+ # Get the name of the binary that Pry.config.editor points to.
144
+ #
145
+ # This is useful for deciding which flags we pass to the editor as
146
+ # we can just use the program's name and ignore any absolute paths.
147
+ #
148
+ # @example
149
+ # Pry.config.editor="/home/conrad/bin/textmate -w"
150
+ # editor_name
151
+ # # => textmate
152
+ #
153
+ def editor_name
154
+ File.basename(pry_instance.config.editor).split(" ").first
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ # Env is a helper module to work with environment variables.
5
+ #
6
+ # @since v0.13.0
7
+ # @api private
8
+ module Env
9
+ def self.[](key)
10
+ return unless ENV.key?(key)
11
+
12
+ value = ENV[key]
13
+ return if value == ''
14
+
15
+ value
16
+ end
17
+ end
18
+ end