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