pry 0.12.0 → 0.14.0

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 (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -1
  3. data/LICENSE +1 -1
  4. data/README.md +331 -269
  5. data/bin/pry +5 -0
  6. data/lib/pry.rb +132 -119
  7. data/lib/pry/basic_object.rb +8 -4
  8. data/lib/pry/block_command.rb +22 -0
  9. data/lib/pry/class_command.rb +194 -0
  10. data/lib/pry/cli.rb +43 -51
  11. data/lib/pry/code.rb +40 -28
  12. data/lib/pry/code/code_file.rb +28 -24
  13. data/lib/pry/code/code_range.rb +4 -2
  14. data/lib/pry/code/loc.rb +15 -8
  15. data/lib/pry/code_object.rb +40 -38
  16. data/lib/pry/color_printer.rb +47 -46
  17. data/lib/pry/command.rb +166 -369
  18. data/lib/pry/command_set.rb +76 -73
  19. data/lib/pry/command_state.rb +31 -0
  20. data/lib/pry/commands/amend_line.rb +86 -81
  21. data/lib/pry/commands/bang.rb +18 -14
  22. data/lib/pry/commands/bang_pry.rb +15 -11
  23. data/lib/pry/commands/cat.rb +61 -54
  24. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  25. data/lib/pry/commands/cat/exception_formatter.rb +71 -60
  26. data/lib/pry/commands/cat/file_formatter.rb +55 -49
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  28. data/lib/pry/commands/cd.rb +40 -35
  29. data/lib/pry/commands/change_inspector.rb +29 -22
  30. data/lib/pry/commands/change_prompt.rb +44 -39
  31. data/lib/pry/commands/clear_screen.rb +16 -10
  32. data/lib/pry/commands/code_collector.rb +148 -133
  33. data/lib/pry/commands/disable_pry.rb +23 -19
  34. data/lib/pry/commands/easter_eggs.rb +19 -30
  35. data/lib/pry/commands/edit.rb +184 -161
  36. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  37. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  38. data/lib/pry/commands/exit.rb +39 -35
  39. data/lib/pry/commands/exit_all.rb +24 -20
  40. data/lib/pry/commands/exit_program.rb +20 -16
  41. data/lib/pry/commands/find_method.rb +168 -160
  42. data/lib/pry/commands/fix_indent.rb +16 -12
  43. data/lib/pry/commands/help.rb +140 -133
  44. data/lib/pry/commands/hist.rb +151 -150
  45. data/lib/pry/commands/import_set.rb +20 -16
  46. data/lib/pry/commands/jump_to.rb +25 -21
  47. data/lib/pry/commands/list_inspectors.rb +35 -28
  48. data/lib/pry/commands/ls.rb +124 -102
  49. data/lib/pry/commands/ls/constants.rb +59 -42
  50. data/lib/pry/commands/ls/formatter.rb +50 -46
  51. data/lib/pry/commands/ls/globals.rb +38 -34
  52. data/lib/pry/commands/ls/grep.rb +17 -13
  53. data/lib/pry/commands/ls/instance_vars.rb +29 -27
  54. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  55. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  56. data/lib/pry/commands/ls/local_names.rb +26 -22
  57. data/lib/pry/commands/ls/local_vars.rb +38 -28
  58. data/lib/pry/commands/ls/ls_entity.rb +47 -51
  59. data/lib/pry/commands/ls/methods.rb +44 -43
  60. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  61. data/lib/pry/commands/ls/self_methods.rb +23 -22
  62. data/lib/pry/commands/nesting.rb +21 -17
  63. data/lib/pry/commands/play.rb +93 -82
  64. data/lib/pry/commands/pry_backtrace.rb +22 -17
  65. data/lib/pry/commands/pry_version.rb +15 -11
  66. data/lib/pry/commands/raise_up.rb +27 -22
  67. data/lib/pry/commands/reload_code.rb +60 -48
  68. data/lib/pry/commands/reset.rb +16 -12
  69. data/lib/pry/commands/ri.rb +55 -45
  70. data/lib/pry/commands/save_file.rb +45 -43
  71. data/lib/pry/commands/shell_command.rb +51 -51
  72. data/lib/pry/commands/shell_mode.rb +21 -17
  73. data/lib/pry/commands/show_doc.rb +80 -68
  74. data/lib/pry/commands/show_info.rb +189 -171
  75. data/lib/pry/commands/show_input.rb +16 -11
  76. data/lib/pry/commands/show_source.rb +110 -45
  77. data/lib/pry/commands/stat.rb +35 -31
  78. data/lib/pry/commands/switch_to.rb +21 -15
  79. data/lib/pry/commands/toggle_color.rb +20 -16
  80. data/lib/pry/commands/watch_expression.rb +89 -86
  81. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  82. data/lib/pry/commands/whereami.rb +156 -148
  83. data/lib/pry/commands/wtf.rb +75 -50
  84. data/lib/pry/config.rb +307 -25
  85. data/lib/pry/config/attributable.rb +22 -0
  86. data/lib/pry/config/lazy_value.rb +29 -0
  87. data/lib/pry/config/memoized_value.rb +34 -0
  88. data/lib/pry/config/value.rb +24 -0
  89. data/lib/pry/control_d_handler.rb +28 -0
  90. data/lib/pry/core_extensions.rb +9 -7
  91. data/lib/pry/editor.rb +48 -21
  92. data/lib/pry/env.rb +18 -0
  93. data/lib/pry/exception_handler.rb +43 -0
  94. data/lib/pry/exceptions.rb +13 -16
  95. data/lib/pry/forwardable.rb +5 -1
  96. data/lib/pry/helpers.rb +2 -0
  97. data/lib/pry/helpers/base_helpers.rb +68 -197
  98. data/lib/pry/helpers/command_helpers.rb +50 -61
  99. data/lib/pry/helpers/documentation_helpers.rb +20 -13
  100. data/lib/pry/helpers/options_helpers.rb +14 -7
  101. data/lib/pry/helpers/platform.rb +7 -5
  102. data/lib/pry/helpers/table.rb +33 -26
  103. data/lib/pry/helpers/text.rb +17 -14
  104. data/lib/pry/history.rb +48 -56
  105. data/lib/pry/hooks.rb +21 -12
  106. data/lib/pry/indent.rb +54 -50
  107. data/lib/pry/input_completer.rb +248 -230
  108. data/lib/pry/input_lock.rb +8 -9
  109. data/lib/pry/inspector.rb +36 -24
  110. data/lib/pry/last_exception.rb +45 -45
  111. data/lib/pry/method.rb +141 -94
  112. data/lib/pry/method/disowned.rb +16 -4
  113. data/lib/pry/method/patcher.rb +12 -3
  114. data/lib/pry/method/weird_method_locator.rb +68 -44
  115. data/lib/pry/object_path.rb +33 -25
  116. data/lib/pry/output.rb +121 -35
  117. data/lib/pry/pager.rb +186 -180
  118. data/lib/pry/prompt.rb +123 -54
  119. data/lib/pry/pry_class.rb +61 -103
  120. data/lib/pry/pry_instance.rb +217 -215
  121. data/lib/pry/repl.rb +18 -22
  122. data/lib/pry/repl_file_loader.rb +27 -21
  123. data/lib/pry/ring.rb +11 -6
  124. data/lib/pry/slop.rb +574 -563
  125. data/lib/pry/slop/commands.rb +164 -169
  126. data/lib/pry/slop/option.rb +172 -168
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable.rb +59 -61
  130. data/lib/pry/testable/evalable.rb +21 -12
  131. data/lib/pry/testable/mockable.rb +18 -10
  132. data/lib/pry/testable/pry_tester.rb +71 -56
  133. data/lib/pry/testable/utility.rb +29 -21
  134. data/lib/pry/testable/variables.rb +49 -43
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +27 -0
  137. data/lib/pry/wrapped_module.rb +51 -42
  138. data/lib/pry/wrapped_module/candidate.rb +21 -14
  139. metadata +35 -35
  140. data/lib/pry/commands.rb +0 -6
  141. data/lib/pry/commands/disabled_commands.rb +0 -2
  142. data/lib/pry/commands/gem_cd.rb +0 -26
  143. data/lib/pry/commands/gem_install.rb +0 -32
  144. data/lib/pry/commands/gem_list.rb +0 -33
  145. data/lib/pry/commands/gem_open.rb +0 -29
  146. data/lib/pry/commands/gem_readme.rb +0 -25
  147. data/lib/pry/commands/gem_search.rb +0 -40
  148. data/lib/pry/commands/gem_stats.rb +0 -83
  149. data/lib/pry/commands/gist.rb +0 -102
  150. data/lib/pry/commands/install_command.rb +0 -54
  151. data/lib/pry/config/behavior.rb +0 -255
  152. data/lib/pry/config/convenience.rb +0 -28
  153. data/lib/pry/config/default.rb +0 -159
  154. data/lib/pry/config/memoization.rb +0 -48
  155. data/lib/pry/platform.rb +0 -91
  156. data/lib/pry/plugins.rb +0 -122
  157. data/lib/pry/rubygem.rb +0 -84
  158. data/lib/pry/terminal.rb +0 -91
@@ -1,70 +1,95 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pry
2
- class Command::Wtf < Pry::ClassCommand
3
- match(/wtf([?!]*)/)
4
- group 'Context'
5
- description 'Show the backtrace of the most recent exception.'
6
- options listing: 'wtf?'
4
+ class Command
5
+ class Wtf < Pry::ClassCommand
6
+ match(/wtf([?!]*)/)
7
+ group 'Context'
8
+ description 'Show the backtrace of the most recent exception.'
9
+ options listing: 'wtf?'
7
10
 
8
- banner <<-'BANNER'
9
- Usage: wtf[?|!]
11
+ banner <<-'BANNER'
12
+ Usage: wtf[?|!]
10
13
 
11
- Show's a few lines of the backtrace of the most recent exception (also available
12
- as `_ex_.backtrace`). If you want to see more lines, add more question marks or
13
- exclamation marks.
14
+ Shows a few lines of the backtrace of the most recent exception (also available
15
+ as `_ex_.backtrace`). If you want to see more lines, add more question marks or
16
+ exclamation marks.
14
17
 
15
- wtf?
16
- wtf?!???!?!?
18
+ wtf?
19
+ wtf?!???!?!?
17
20
 
18
- # To see the entire backtrace, pass the `-v` or `--verbose` flag.
19
- wtf -v
20
- BANNER
21
+ # To see the entire backtrace, pass the `-v` or `--verbose` flag.
22
+ wtf -v
23
+ BANNER
21
24
 
22
- def options(opt)
23
- opt.on :v, :verbose, "Show the full backtrace"
24
- end
25
+ RUBY_FRAME_PATTERN = /\A(?<file>(.+)):(?<line>(\d+))/.freeze
26
+
27
+ def options(opt)
28
+ opt.on :v, :verbose, "Show the full backtrace"
29
+ opt.on :c, :code, "Show code corresponding to the backtrace frame"
30
+ end
25
31
 
26
- def process
27
- raise Pry::CommandError, "No most-recent exception" unless exception
32
+ def process
33
+ unless pry_instance.last_exception
34
+ raise Pry::CommandError, "No most-recent exception"
35
+ end
28
36
 
29
- output.puts "#{bold('Exception:')} #{exception.class}: #{exception}\n--"
30
- if opts.verbose?
31
- output.puts with_line_numbers(backtrace)
32
- else
33
- output.puts with_line_numbers(backtrace.first(size_of_backtrace))
37
+ text = ''.dup
38
+ unwind_exceptions.each_with_index do |exception, i|
39
+ title = (i == 0 ? 'Exception' : 'Caused by')
40
+ text << format_header(title, exception)
41
+ text << format_backtrace(exception.backtrace)
42
+ end
43
+ output.puts(text)
34
44
  end
35
45
 
36
- if exception.respond_to? :cause
37
- cause = exception.cause
38
- while cause
39
- output.puts "#{text.bold('Caused by:')} #{cause.class}: #{cause}\n--"
40
- if opts.verbose?
41
- output.puts with_line_numbers(cause.backtrace)
42
- else
43
- output.puts with_line_numbers(cause.backtrace.first(size_of_backtrace))
44
- end
45
- cause = cause.cause
46
+ private
47
+
48
+ def unwind_exceptions
49
+ exception_list = []
50
+ exception = pry_instance.last_exception
51
+
52
+ while exception
53
+ exception_list << exception
54
+ exception = (exception.cause if exception.respond_to?(:cause))
46
55
  end
56
+
57
+ exception_list
47
58
  end
48
- end
49
59
 
50
- private
60
+ def format_header(title, exception)
61
+ "#{bold(title + ':')} #{exception.class}: #{exception}\n--\n"
62
+ end
51
63
 
52
- def exception
53
- _pry_.last_exception
54
- end
64
+ def format_backtrace(backtrace)
65
+ lines = trim_backtrace(backtrace).map do |frame|
66
+ next frame unless opts.code?
55
67
 
56
- def with_line_numbers(bt)
57
- Pry::Code.new(bt, 0, :text).with_line_numbers.to_s
58
- end
68
+ match = frame.match(RUBY_FRAME_PATTERN)
69
+ code = read_line(match[:file], match[:line].to_i)
70
+ [bold(frame), code].join("\n")
71
+ end
59
72
 
60
- def backtrace
61
- exception.backtrace
62
- end
73
+ Pry::Code.new(lines.compact, 0, :text).with_line_numbers.to_s
74
+ end
75
+
76
+ def trim_backtrace(backtrace)
77
+ return backtrace if opts.verbose?
63
78
 
64
- def size_of_backtrace
65
- [captures[0].size, 0.5].max * 10
79
+ size_of_backtrace = [captures[0].size, 0.5].max * 10
80
+ backtrace.first(size_of_backtrace)
81
+ end
82
+
83
+ def read_line(file, line)
84
+ File.open(file, 'r') do |f|
85
+ (line - 1).times { f.gets }
86
+ f.gets
87
+ end
88
+ rescue Errno::ENOENT
89
+ nil
90
+ end
66
91
  end
67
- end
68
92
 
69
- Pry::Commands.add_command(Pry::Command::Wtf)
93
+ Pry::Commands.add_command(Pry::Command::Wtf)
94
+ end
70
95
  end
data/lib/pry/config.rb CHANGED
@@ -1,35 +1,317 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
1
5
  class Pry
2
- # The Pry config.
3
- # @api public
4
- class Config < Pry::BasicObject
5
- # Wraps a block so it can have a name.
6
- #
7
- # @example
8
- # proc1 = proc {}
9
- # proc2 = Pry::Config::Lazy.new(&proc {})
10
- #
11
- # proc1.is_a?(Pry::Config::Lazy)
12
- # #=> false
13
- # proc2.is_a?(Pry::Config::Lazy)
14
- # #=> true
6
+ # @api private
7
+ class Config
8
+ extend Attributable
9
+
10
+ # @return [IO, #readline] he object from which Pry retrieves its lines of
11
+ # input
12
+ attribute :input
13
+
14
+ # @return [IO, #puts] where Pry should output results provided by {input}
15
+ attribute :output
16
+
17
+ # @return [Pry::CommandSet]
18
+ attribute :commands
19
+
20
+ # @return [Proc] the printer for Ruby expressions (not commands)
21
+ attribute :print
22
+
23
+ # @return [Proc] the printer for exceptions
24
+ attribute :exception_handler
25
+
26
+ # @return [Array] Exception that Pry shouldn't rescue
27
+ attribute :unrescued_exceptions
28
+
29
+ # @deprecated
30
+ # @return [Array] Exception that Pry shouldn't rescue
31
+ attribute :exception_whitelist
32
+
33
+ # @return [Integer] The number of lines of context to show before and after
34
+ # exceptions
35
+ attribute :default_window_size
36
+
37
+ # @return [Pry::Hooks]
38
+ attribute :hooks
39
+
40
+ # @return [Pry::Prompt]
41
+ attribute :prompt
42
+
43
+ # @return [String] The display name that is part of the prompt
44
+ attribute :prompt_name
45
+
46
+ # @return [Array<Object>] the list of objects that are known to have a
47
+ # 1-line #inspect output suitable for prompt
48
+ attribute :prompt_safe_contexts
49
+
50
+ # If it is a String, then that String is used as the shell
51
+ # command to invoke the editor.
15
52
  #
16
- # @api private
17
- # @since v0.12.0
18
- class Lazy
19
- def initialize(&block)
20
- @block = block
21
- end
53
+ # If it responds to #call is callable then `file`, `line`, and `reloading`
54
+ # are passed to it. `reloading` indicates whether Pry will be reloading code
55
+ # after the shell command returns. All parameters are optional.
56
+ # @return [String, #call]
57
+ attribute :editor
58
+
59
+ # A string that must precede all commands. For example, if is is
60
+ # set to "%", the "cd" command must be invoked as "%cd").
61
+ # @return [String]
62
+ attribute :command_prefix
63
+
64
+ # @return [Boolean]
65
+ attribute :color
66
+
67
+ # @return [Boolean]
68
+ attribute :pager
69
+
70
+ # @return [Boolean] whether the global ~/.pryrc should be loaded
71
+ attribute :should_load_rc
72
+
73
+ # @return [Boolean] whether the local ./.pryrc should be loaded
74
+ attribute :should_load_local_rc
75
+
76
+ # @return [Boolean] whether to load files specified with the -r flag
77
+ attribute :should_load_requires
78
+
79
+ # @return [Boolean] whether to disable edit-method's auto-reloading behavior
80
+ attribute :disable_auto_reload
81
+
82
+ # Whether Pry should trap SIGINT and cause it to raise an Interrupt
83
+ # exception. This is only useful on JRuby, MRI does this for us.
84
+ # @return [Boolean]
85
+ attribute :should_trap_interrupts
86
+
87
+ # @return [Pry::History]
88
+ attribute :history
89
+
90
+ # @return [Boolean]
91
+ attribute :history_save
92
+
93
+ # @return [Boolean]
94
+ attribute :history_load
95
+
96
+ # @return [String]
97
+ attribute :history_file
98
+
99
+ # @return [Array<String,Regexp>]
100
+ attribute :history_ignorelist
101
+
102
+ # @return [Array<String>] Ruby files to be required
103
+ attribute :requires
104
+
105
+ # @return [Integer] how many input/output lines to keep in memory
106
+ attribute :memory_size
107
+
108
+ # @return [Proc] The proc that runs system commands
109
+ attribute :system
110
+
111
+ # @return [Boolean]
112
+ attribute :auto_indent
113
+
114
+ # @return [Boolean]
115
+ attribute :correct_indent
22
116
 
23
- # @return [Object]
24
- def call
25
- @block.call
117
+ # @return [Boolean] whether or not display a warning when a command name
118
+ # collides with a method/local in the current context.
119
+ attribute :collision_warning
120
+
121
+ # @return [Hash{Symbol=>Proc}]
122
+ attribute :extra_sticky_locals
123
+
124
+ # @return [#build_completion_proc] a completer to use
125
+ attribute :completer
126
+
127
+ # @return [Boolean] suppresses whereami output on `binding.pry`
128
+ attribute :quiet
129
+
130
+ # @return [Boolean] displays a warning about experience improvement on
131
+ # Windows
132
+ attribute :windows_console_warning
133
+
134
+ # @return [Proc]
135
+ attribute :command_completions
136
+
137
+ # @return [Proc]
138
+ attribute :file_completions
139
+
140
+ # @return [Hash]
141
+ attribute :ls
142
+
143
+ # @return [String] a line of code to execute in context before the session
144
+ # starts
145
+ attribute :exec_string
146
+
147
+ # @return [String]
148
+ attribute :output_prefix
149
+
150
+ # @return [String]
151
+ # @since v0.13.0
152
+ attribute :rc_file
153
+
154
+ def initialize
155
+ merge!(
156
+ input: MemoizedValue.new { lazy_readline },
157
+ output: $stdout.tap { |out| out.sync = true },
158
+ commands: Pry::Commands,
159
+ prompt_name: 'pry',
160
+ prompt: Pry::Prompt[:default],
161
+ prompt_safe_contexts: [String, Numeric, Symbol, nil, true, false],
162
+ print: Pry::ColorPrinter.method(:default),
163
+ quiet: false,
164
+ exception_handler: Pry::ExceptionHandler.method(:handle_exception),
165
+
166
+ unrescued_exceptions: [
167
+ ::SystemExit, ::SignalException, Pry::TooSafeException
168
+ ],
169
+
170
+ exception_whitelist: MemoizedValue.new do
171
+ output.puts(
172
+ '[warning] Pry.config.exception_whitelist is deprecated, ' \
173
+ 'please use Pry.config.unrescued_exceptions instead.'
174
+ )
175
+ unrescued_exceptions
176
+ end,
177
+
178
+ hooks: Pry::Hooks.default,
179
+ pager: true,
180
+ system: Pry::SystemCommandHandler.method(:default),
181
+ color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
182
+ default_window_size: 5,
183
+ editor: Pry::Editor.default,
184
+ rc_file: default_rc_file,
185
+ should_load_rc: true,
186
+ should_load_local_rc: true,
187
+ should_trap_interrupts: Pry::Helpers::Platform.jruby?,
188
+ disable_auto_reload: false,
189
+ command_prefix: '',
190
+ auto_indent: Pry::Helpers::BaseHelpers.use_ansi_codes?,
191
+ correct_indent: true,
192
+ collision_warning: false,
193
+ output_prefix: '=> ',
194
+ requires: [],
195
+ should_load_requires: true,
196
+ windows_console_warning: true,
197
+ control_d_handler: Pry::ControlDHandler.method(:default),
198
+ memory_size: 100,
199
+ extra_sticky_locals: {},
200
+ command_completions: proc { commands.keys },
201
+ file_completions: proc { Dir['.'] },
202
+ ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS),
203
+ completer: Pry::InputCompleter,
204
+ history_save: true,
205
+ history_load: true,
206
+ history_file: Pry::History.default_file,
207
+ history_ignorelist: [],
208
+ history: MemoizedValue.new do
209
+ if defined?(input::HISTORY)
210
+ Pry::History.new(history: input::HISTORY)
211
+ else
212
+ Pry::History.new
213
+ end
214
+ end,
215
+ exec_string: ''
216
+ )
217
+
218
+ @custom_attrs = {}
219
+ end
220
+
221
+ def merge!(config_hash)
222
+ config_hash.each_pair { |attr, value| __send__("#{attr}=", value) }
223
+ self
224
+ end
225
+
226
+ def merge(config_hash)
227
+ dup.merge!(config_hash)
228
+ end
229
+
230
+ def []=(attr, value)
231
+ @custom_attrs[attr.to_s] = Config::Value.new(value)
232
+ end
233
+
234
+ def [](attr)
235
+ @custom_attrs[attr.to_s].call
236
+ end
237
+
238
+ # rubocop:disable Style/MethodMissingSuper
239
+ def method_missing(method_name, *args, &_block)
240
+ name = method_name.to_s
241
+
242
+ if name.end_with?('=')
243
+ self[name[0..-2]] = args.first
244
+ elsif @custom_attrs.key?(name)
245
+ self[name]
26
246
  end
27
247
  end
248
+ # rubocop:enable Style/MethodMissingSuper
28
249
 
29
- include Behavior
250
+ def respond_to_missing?(method_name, include_all = false)
251
+ @custom_attrs.key?(method_name.to_s.tr('=', '')) || super
252
+ end
30
253
 
31
- def self.shortcuts
32
- Convenience::SHORTCUTS
254
+ def initialize_dup(other)
255
+ super
256
+ @custom_attrs = @custom_attrs.dup
257
+ end
258
+
259
+ attr_reader :control_d_handler
260
+ def control_d_handler=(value)
261
+ proxy_proc =
262
+ if value.arity == 2
263
+ Pry::Warning.warn(
264
+ "control_d_handler's arity of 2 parameters was deprecated " \
265
+ '(eval_string, pry_instance). Now it gets passed just 1 ' \
266
+ 'parameter (pry_instance)'
267
+ )
268
+ proc do |*args|
269
+ if args.size == 2
270
+ value.call(args.first, args[1])
271
+ else
272
+ value.call(args.first.eval_string, args.first)
273
+ end
274
+ end
275
+ else
276
+ proc do |*args|
277
+ if args.size == 2
278
+ value.call(args[1])
279
+ else
280
+ value.call(args.first)
281
+ end
282
+ end
283
+ end
284
+ @control_d_handler = proxy_proc
285
+ end
286
+
287
+ private
288
+
289
+ def lazy_readline
290
+ require 'readline'
291
+ ::Readline
292
+ rescue LoadError
293
+ output.puts(
294
+ "Sorry, you can't use Pry without Readline or a compatible library. \n" \
295
+ "Possible solutions: \n" \
296
+ " * Rebuild Ruby with Readline support using `--with-readline` \n" \
297
+ " * Use the rb-readline gem, which is a pure-Ruby port of Readline \n" \
298
+ " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
299
+ )
300
+ raise
301
+ end
302
+
303
+ def default_rc_file
304
+ if (pryrc = Pry::Env['PRYRC'])
305
+ pryrc
306
+ elsif (xdg_home = Pry::Env['XDG_CONFIG_HOME'])
307
+ # See XDG Base Directory Specification at
308
+ # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
309
+ xdg_home + '/pry/pryrc'
310
+ elsif File.exist?(File.expand_path('~/.pryrc'))
311
+ '~/.pryrc'
312
+ else
313
+ '~/.config/pry/pryrc'
314
+ end
33
315
  end
34
316
  end
35
317
  end