pry 0.10.3 → 0.12.2
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 +4 -4
- data/CHANGELOG.md +251 -16
- data/LICENSE +1 -1
- data/README.md +35 -51
- data/bin/pry +3 -11
- data/lib/pry/basic_object.rb +6 -0
- data/lib/pry/cli.rb +50 -52
- data/lib/pry/code/code_file.rb +13 -6
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code.rb +12 -5
- data/lib/pry/code_object.rb +27 -4
- data/lib/pry/color_printer.rb +20 -10
- data/lib/pry/command.rb +76 -45
- data/lib/pry/command_set.rb +17 -45
- data/lib/pry/commands/amend_line.rb +3 -4
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat/exception_formatter.rb +10 -8
- data/lib/pry/commands/cat/file_formatter.rb +7 -3
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cat.rb +7 -6
- data/lib/pry/commands/change_prompt.rb +29 -9
- data/lib/pry/commands/clear_screen.rb +14 -0
- data/lib/pry/commands/code_collector.rb +25 -23
- data/lib/pry/commands/easter_eggs.rb +12 -12
- data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
- data/lib/pry/commands/edit.rb +15 -10
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +12 -14
- data/lib/pry/commands/gem_cd.rb +1 -1
- data/lib/pry/commands/gem_install.rb +2 -2
- data/lib/pry/commands/gem_list.rb +2 -2
- data/lib/pry/commands/gem_open.rb +2 -2
- data/lib/pry/commands/gem_readme.rb +25 -0
- data/lib/pry/commands/gem_search.rb +40 -0
- data/lib/pry/commands/gem_stats.rb +83 -0
- data/lib/pry/commands/gist.rb +7 -6
- data/lib/pry/commands/help.rb +3 -3
- data/lib/pry/commands/hist.rb +11 -10
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/jump_to.rb +7 -7
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls/constants.rb +14 -3
- data/lib/pry/commands/ls/formatter.rb +4 -2
- data/lib/pry/commands/ls/globals.rb +0 -2
- data/lib/pry/commands/ls/grep.rb +0 -2
- data/lib/pry/commands/ls/instance_vars.rb +0 -1
- data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
- data/lib/pry/commands/ls/local_names.rb +0 -2
- data/lib/pry/commands/ls/local_vars.rb +0 -2
- data/lib/pry/commands/ls/ls_entity.rb +0 -1
- data/lib/pry/commands/ls/methods.rb +0 -3
- data/lib/pry/commands/ls/methods_helper.rb +1 -1
- data/lib/pry/commands/ls/self_methods.rb +2 -1
- data/lib/pry/commands/ls.rb +30 -31
- data/lib/pry/commands/play.rb +3 -4
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/reload_code.rb +2 -2
- data/lib/pry/commands/ri.rb +9 -4
- data/lib/pry/commands/shell_command.rb +36 -9
- data/lib/pry/commands/shell_mode.rb +6 -6
- data/lib/pry/commands/show_doc.rb +5 -7
- data/lib/pry/commands/show_info.rb +41 -20
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression/expression.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +16 -9
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config/behavior.rb +230 -114
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +151 -153
- data/lib/pry/config/memoization.rb +48 -0
- data/lib/pry/config.rb +30 -19
- data/lib/pry/core_extensions.rb +15 -4
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +1 -3
- data/lib/pry/forwardable.rb +23 -0
- data/lib/pry/helpers/base_helpers.rb +197 -110
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +3 -2
- data/lib/pry/helpers/options_helpers.rb +6 -6
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +82 -74
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/history.rb +44 -10
- data/lib/pry/hooks.rb +50 -109
- data/lib/pry/indent.rb +21 -19
- data/lib/pry/input_completer.rb +146 -123
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +2 -2
- data/lib/pry/method/disowned.rb +3 -1
- data/lib/pry/method/patcher.rb +2 -5
- data/lib/pry/method/weird_method_locator.rb +21 -11
- data/lib/pry/method.rb +44 -38
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +37 -37
- data/lib/pry/pager.rb +195 -181
- data/lib/pry/platform.rb +91 -0
- data/lib/pry/plugins.rb +27 -8
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +83 -33
- data/lib/pry/pry_instance.rb +94 -59
- data/lib/pry/repl.rb +70 -11
- data/lib/pry/repl_file_loader.rb +2 -3
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +9 -7
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +195 -0
- data/lib/pry/slop/option.rb +206 -0
- data/lib/pry/slop.rb +661 -0
- data/lib/pry/terminal.rb +18 -6
- data/lib/pry/testable/evalable.rb +15 -0
- data/lib/pry/testable/mockable.rb +14 -0
- data/lib/pry/testable/pry_tester.rb +73 -0
- data/lib/pry/testable/utility.rb +26 -0
- data/lib/pry/testable/variables.rb +46 -0
- data/lib/pry/testable.rb +70 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +9 -14
- data/lib/pry/wrapped_module.rb +22 -21
- data/lib/pry.rb +21 -50
- metadata +35 -46
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/test/helper.rb +0 -170
data/lib/pry/pager.rb
CHANGED
@@ -3,234 +3,248 @@ require 'pry/terminal'
|
|
3
3
|
# A pager is an `IO`-like object that accepts text and either prints it
|
4
4
|
# immediately, prints it one page at a time, or streams it to an external
|
5
5
|
# program to print one page at a time.
|
6
|
-
class Pry
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
attr_reader :_pry_
|
11
|
-
|
12
|
-
def initialize(_pry_)
|
13
|
-
@_pry_ = _pry_
|
14
|
-
end
|
15
|
-
|
16
|
-
# Send the given text through the best available pager (if `Pry.config.pager` is
|
17
|
-
# enabled).
|
18
|
-
# If you want to send text through in chunks as you generate it, use `open` to
|
19
|
-
# get a writable object instead.
|
20
|
-
# @param [String] text A piece of text to run through a pager.
|
21
|
-
# @param [IO] output (`$stdout`) An object to send output to.
|
22
|
-
def page(text)
|
23
|
-
open do |pager|
|
24
|
-
pager << text
|
6
|
+
class Pry
|
7
|
+
class Pager
|
8
|
+
class StopPaging < StandardError
|
25
9
|
end
|
26
|
-
end
|
27
10
|
|
28
|
-
|
29
|
-
# pagers accept output with `#puts`, `#print`, `#write`, and `#<<`.
|
30
|
-
# @param [IO] output (`$stdout`) An object to send output to.
|
31
|
-
def open
|
32
|
-
pager = best_available
|
33
|
-
yield pager
|
34
|
-
rescue StopPaging
|
35
|
-
ensure
|
36
|
-
pager.close if pager
|
37
|
-
end
|
11
|
+
attr_reader :_pry_
|
38
12
|
|
39
|
-
|
40
|
-
|
41
|
-
def enabled?; !!@enabled; end
|
42
|
-
|
43
|
-
def output; @output; end
|
44
|
-
|
45
|
-
# Return an instance of the "best" available pager class -- `SystemPager` if
|
46
|
-
# possible, `SimplePager` if `SystemPager` isn't available, and `NullPager`
|
47
|
-
# if the user has disabled paging. All pagers accept output with `#puts`,
|
48
|
-
# `#print`, `#write`, and `#<<`. You must call `#close` when you're done
|
49
|
-
# writing output to a pager, and you must rescue `Pry::Pager::StopPaging`.
|
50
|
-
# These requirements can be avoided by using `.open` instead.
|
51
|
-
# @param [#<<] output ($stdout) An object to send output to.
|
52
|
-
def best_available
|
53
|
-
if !_pry_.config.pager
|
54
|
-
NullPager.new(_pry_.output)
|
55
|
-
elsif !SystemPager.available? || Pry::Helpers::BaseHelpers.jruby?
|
56
|
-
SimplePager.new(_pry_.output)
|
57
|
-
else
|
58
|
-
SystemPager.new(_pry_.output)
|
13
|
+
def initialize(_pry_)
|
14
|
+
@_pry_ = _pry_
|
59
15
|
end
|
60
|
-
end
|
61
16
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
17
|
+
# Send the given text through the best available pager (if
|
18
|
+
# `Pry.config.pager` is enabled). If you want to send text through in
|
19
|
+
# chunks as you generate it, use `open` to get a writable object
|
20
|
+
# instead.
|
21
|
+
#
|
22
|
+
# @param [String] text
|
23
|
+
# Text to run through a pager.
|
24
|
+
#
|
25
|
+
def page(text)
|
26
|
+
open do |pager|
|
27
|
+
pager << text
|
28
|
+
end
|
67
29
|
end
|
68
30
|
|
69
|
-
|
70
|
-
|
31
|
+
# Yields a pager object (`NullPager`, `SimplePager`, or `SystemPager`).
|
32
|
+
# All pagers accept output with `#puts`, `#print`, `#write`, and `#<<`.
|
33
|
+
def open
|
34
|
+
pager = best_available
|
35
|
+
yield pager
|
36
|
+
rescue StopPaging
|
37
|
+
ensure
|
38
|
+
pager.close if pager
|
71
39
|
end
|
72
40
|
|
73
|
-
|
74
|
-
write str
|
75
|
-
end
|
76
|
-
alias << print
|
41
|
+
private
|
77
42
|
|
78
|
-
def
|
79
|
-
|
43
|
+
def enabled?; !!@enabled; end
|
44
|
+
|
45
|
+
def output; @output; end
|
46
|
+
|
47
|
+
# Return an instance of the "best" available pager class --
|
48
|
+
# `SystemPager` if possible, `SimplePager` if `SystemPager` isn't
|
49
|
+
# available, and `NullPager` if the user has disabled paging. All
|
50
|
+
# pagers accept output with `#puts`, `#print`, `#write`, and `#<<`. You
|
51
|
+
# must call `#close` when you're done writing output to a pager, and
|
52
|
+
# you must rescue `Pry::Pager::StopPaging`. These requirements can be
|
53
|
+
# avoided by using `.open` instead.
|
54
|
+
def best_available
|
55
|
+
if !_pry_.config.pager
|
56
|
+
NullPager.new(_pry_.output)
|
57
|
+
elsif !SystemPager.available? || Helpers::Platform.jruby?
|
58
|
+
SimplePager.new(_pry_.output)
|
59
|
+
else
|
60
|
+
SystemPager.new(_pry_.output)
|
61
|
+
end
|
80
62
|
end
|
81
63
|
|
82
|
-
|
83
|
-
|
64
|
+
# `NullPager` is a "pager" that actually just prints all output as it
|
65
|
+
# comes in. Used when `Pry.config.pager` is false.
|
66
|
+
class NullPager
|
67
|
+
def initialize(out)
|
68
|
+
@out = out
|
69
|
+
end
|
84
70
|
|
85
|
-
|
71
|
+
def puts(str)
|
72
|
+
print "#{str.chomp}\n"
|
73
|
+
end
|
86
74
|
|
87
|
-
|
88
|
-
|
89
|
-
|
75
|
+
def print(str)
|
76
|
+
write str
|
77
|
+
end
|
78
|
+
alias << print
|
90
79
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
80
|
+
def write(str)
|
81
|
+
@out.write str
|
82
|
+
end
|
83
|
+
|
84
|
+
def close
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
95
88
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
89
|
+
def height
|
90
|
+
@height ||= Pry::Terminal.height!
|
91
|
+
end
|
92
|
+
|
93
|
+
def width
|
94
|
+
@width ||= Pry::Terminal.width!
|
95
|
+
end
|
102
96
|
end
|
103
97
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
@tracker.
|
98
|
+
# `SimplePager` is a straightforward pure-Ruby pager. We use it on
|
99
|
+
# JRuby and when we can't find a usable external pager.
|
100
|
+
class SimplePager < NullPager
|
101
|
+
def initialize(*)
|
102
|
+
super
|
103
|
+
@tracker = PageTracker.new(height - 3, width)
|
104
|
+
end
|
105
|
+
|
106
|
+
def write(str)
|
107
|
+
str.lines.each do |line|
|
108
|
+
@out.print line
|
109
|
+
@tracker.record line
|
110
|
+
|
111
|
+
if @tracker.page?
|
112
|
+
@out.print "\n"
|
113
|
+
@out.print "\e[0m"
|
114
|
+
@out.print "<page break> --- Press enter to continue " \
|
115
|
+
"( q<enter> to break ) --- <page break>\n"
|
116
|
+
raise StopPaging if Readline.readline("").chomp == "q"
|
117
|
+
|
118
|
+
@tracker.reset
|
119
|
+
end
|
116
120
|
end
|
117
121
|
end
|
118
122
|
end
|
119
|
-
end
|
120
123
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
# `SystemPager` buffers output until we're pretty sure it's at least a
|
125
|
+
# page long, then invokes an external pager and starts streaming output
|
126
|
+
# to it. If `#close` is called before then, it just prints out the
|
127
|
+
# buffered content.
|
128
|
+
class SystemPager < NullPager
|
129
|
+
def self.default_pager
|
130
|
+
pager = ENV["PAGER"] || ""
|
127
131
|
|
128
|
-
|
129
|
-
|
130
|
-
pager
|
131
|
-
|
132
|
+
# Default to less, and make sure less is being passed the correct
|
133
|
+
# options
|
134
|
+
if pager.strip.empty? or pager =~ /^less\b/
|
135
|
+
pager = "less -R -F -X"
|
136
|
+
end
|
132
137
|
|
133
|
-
|
134
|
-
|
138
|
+
pager
|
139
|
+
end
|
135
140
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
@system_pager = nil
|
142
|
+
|
143
|
+
def self.available?
|
144
|
+
if @system_pager.nil?
|
145
|
+
@system_pager = begin
|
146
|
+
pager_executable = default_pager.split(' ').first
|
147
|
+
if Helpers::Platform.windows? || Helpers::Platform.windows_ansi?
|
148
|
+
`where /Q #{pager_executable}`
|
149
|
+
else
|
150
|
+
`which #{pager_executable}`
|
151
|
+
end
|
152
|
+
$?.success?
|
153
|
+
rescue
|
154
|
+
false
|
155
|
+
end
|
156
|
+
else
|
157
|
+
@system_pager
|
144
158
|
end
|
145
|
-
else
|
146
|
-
@system_pager
|
147
159
|
end
|
148
|
-
end
|
149
160
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
161
|
+
def initialize(*)
|
162
|
+
super
|
163
|
+
@tracker = PageTracker.new(height, width)
|
164
|
+
@buffer = ""
|
165
|
+
@pager = nil
|
166
|
+
end
|
155
167
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
168
|
+
def write(str)
|
169
|
+
if invoked_pager?
|
170
|
+
write_to_pager str
|
171
|
+
else
|
172
|
+
@tracker.record str
|
173
|
+
@buffer << str
|
162
174
|
|
163
|
-
|
164
|
-
|
175
|
+
if @tracker.page?
|
176
|
+
write_to_pager @buffer
|
177
|
+
end
|
165
178
|
end
|
179
|
+
rescue Errno::EPIPE
|
180
|
+
raise StopPaging
|
166
181
|
end
|
167
|
-
rescue Errno::EPIPE
|
168
|
-
raise StopPaging
|
169
|
-
end
|
170
182
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
183
|
+
def close
|
184
|
+
if invoked_pager?
|
185
|
+
pager.close
|
186
|
+
else
|
187
|
+
@out.puts @buffer
|
188
|
+
end
|
176
189
|
end
|
177
|
-
end
|
178
190
|
|
179
|
-
|
191
|
+
private
|
180
192
|
|
181
|
-
|
182
|
-
|
183
|
-
|
193
|
+
def write_to_pager(text)
|
194
|
+
pager.write @out.decolorize_maybe(text)
|
195
|
+
end
|
184
196
|
|
185
|
-
|
186
|
-
|
187
|
-
|
197
|
+
def invoked_pager?
|
198
|
+
@pager
|
199
|
+
end
|
188
200
|
|
189
|
-
|
190
|
-
|
201
|
+
def pager
|
202
|
+
@pager ||= IO.popen(self.class.default_pager, 'w')
|
203
|
+
end
|
191
204
|
end
|
192
|
-
end
|
193
205
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
206
|
+
# `PageTracker` tracks output to determine whether it's likely to take
|
207
|
+
# up a whole page. This doesn't need to be super precise, but we can
|
208
|
+
# use it for `SimplePager` and to avoid invoking the system pager
|
209
|
+
# unnecessarily.
|
210
|
+
#
|
211
|
+
# One simplifying assumption is that we don't need `#page?` to return
|
212
|
+
# `true` on the basis of an incomplete line. Long lines should be
|
213
|
+
# counted as multiple lines, but we don't have to transition from
|
214
|
+
# `false` to `true` until we see a newline.
|
215
|
+
class PageTracker
|
216
|
+
def initialize(rows, cols)
|
217
|
+
@rows, @cols = rows, cols
|
218
|
+
reset
|
219
|
+
end
|
207
220
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
221
|
+
def record(str)
|
222
|
+
str.lines.each do |line|
|
223
|
+
if line.end_with? "\n"
|
224
|
+
@row += ((@col + line_length(line) - 1) / @cols) + 1
|
225
|
+
@col = 0
|
226
|
+
else
|
227
|
+
@col += line_length(line)
|
228
|
+
end
|
215
229
|
end
|
216
230
|
end
|
217
|
-
end
|
218
231
|
|
219
|
-
|
220
|
-
|
221
|
-
|
232
|
+
def page?
|
233
|
+
@row >= @rows
|
234
|
+
end
|
222
235
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
236
|
+
def reset
|
237
|
+
@row = 0
|
238
|
+
@col = 0
|
239
|
+
end
|
227
240
|
|
228
|
-
|
241
|
+
private
|
229
242
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
243
|
+
# Approximation of the printable length of a given line, without the
|
244
|
+
# newline and without ANSI color codes.
|
245
|
+
def line_length(line)
|
246
|
+
line.chomp.gsub(/\e\[[\d;]*m/, '').length
|
247
|
+
end
|
234
248
|
end
|
235
249
|
end
|
236
250
|
end
|
data/lib/pry/platform.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
class Pry
|
2
|
+
module Platform
|
3
|
+
extend self
|
4
|
+
|
5
|
+
#
|
6
|
+
# @return [Boolean]
|
7
|
+
# Returns true if Pry is running on Mac OSX.
|
8
|
+
#
|
9
|
+
# @note
|
10
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
11
|
+
#
|
12
|
+
def mac_osx?
|
13
|
+
!!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
18
|
+
# Returns true if Pry is running on Linux.
|
19
|
+
#
|
20
|
+
# @note
|
21
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
22
|
+
#
|
23
|
+
def linux?
|
24
|
+
!!(RbConfig::CONFIG['host_os'] =~ /linux/i)
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# @return [Boolean]
|
29
|
+
# Returns true if Pry is running on Windows.
|
30
|
+
#
|
31
|
+
# @note
|
32
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
33
|
+
#
|
34
|
+
def windows?
|
35
|
+
!!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
# Returns true when Pry is running on Windows with ANSI support.
|
41
|
+
#
|
42
|
+
def windows_ansi?
|
43
|
+
return false if not windows?
|
44
|
+
|
45
|
+
!!(defined?(Win32::Console) or ENV['ANSICON'] or mri_2?)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# @return [Boolean]
|
50
|
+
# Returns true when Pry is being run from JRuby.
|
51
|
+
#
|
52
|
+
def jruby?
|
53
|
+
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# @return [Boolean]
|
58
|
+
# Returns true when Pry is being run from JRuby in 1.9 mode.
|
59
|
+
#
|
60
|
+
def jruby_19?
|
61
|
+
jruby? and RbConfig::CONFIG['ruby_version'] == '1.9'
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# @return [Boolean]
|
66
|
+
# Returns true when Pry is being run from MRI (CRuby).
|
67
|
+
#
|
68
|
+
def mri?
|
69
|
+
RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# @return [Boolean]
|
74
|
+
# Returns true when Pry is being run from MRI v1.9+ (CRuby).
|
75
|
+
#
|
76
|
+
def mri_19?
|
77
|
+
!!(mri? and RUBY_VERSION =~ /\A1\.9/)
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# @return [Boolean]
|
82
|
+
# Returns true when Pry is being run from MRI v2+ (CRuby).
|
83
|
+
#
|
84
|
+
def mri_2?
|
85
|
+
!!(mri? and RUBY_VERSION =~ /\A2/)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Not supported on MRI 2.2 and lower.
|
90
|
+
deprecate_constant(:Platform) if respond_to?(:deprecate_constant)
|
91
|
+
end
|
data/lib/pry/plugins.rb
CHANGED
@@ -8,7 +8,7 @@ class Pry
|
|
8
8
|
@name = name
|
9
9
|
end
|
10
10
|
|
11
|
-
def method_missing(*
|
11
|
+
def method_missing(*_args)
|
12
12
|
warn "Warning: The plugin '#{@name}' was not found! (no gem found)"
|
13
13
|
end
|
14
14
|
end
|
@@ -35,8 +35,12 @@ class Pry
|
|
35
35
|
# Load the Command line options defined by this plugin (if they exist)
|
36
36
|
def load_cli_options
|
37
37
|
cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb")
|
38
|
-
|
38
|
+
return unless File.exist?(cli_options_file)
|
39
|
+
|
40
|
+
cli_options_file = File.realpath(cli_options_file) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4")
|
41
|
+
require cli_options_file
|
39
42
|
end
|
43
|
+
|
40
44
|
# Activate the plugin (require the gem - enables/loads the
|
41
45
|
# plugin immediately at point of call, even if plugin is
|
42
46
|
# disabled)
|
@@ -60,6 +64,16 @@ class Pry
|
|
60
64
|
|
61
65
|
alias active? active
|
62
66
|
alias enabled? enabled
|
67
|
+
|
68
|
+
def supported?
|
69
|
+
pry_version = Gem::Version.new(VERSION)
|
70
|
+
spec.dependencies.each do |dependency|
|
71
|
+
if dependency.name == "pry"
|
72
|
+
return dependency.requirement.satisfied_by?(pry_version)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
true
|
76
|
+
end
|
63
77
|
end
|
64
78
|
|
65
79
|
def initialize
|
@@ -68,11 +82,12 @@ class Pry
|
|
68
82
|
|
69
83
|
# Find all installed Pry plugins and store them in an internal array.
|
70
84
|
def locate_plugins
|
71
|
-
|
72
|
-
(Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
|
85
|
+
gem_list.each do |gem|
|
73
86
|
next if gem.name !~ PRY_PLUGIN_PREFIX
|
87
|
+
|
74
88
|
plugin_name = gem.name.split('-', 2).last
|
75
|
-
|
89
|
+
plugin = Plugin.new(plugin_name, gem.name, gem, false)
|
90
|
+
@plugins << plugin.tap(&:enable!) if plugin.supported? && !plugin_located?(plugin)
|
76
91
|
end
|
77
92
|
@plugins
|
78
93
|
end
|
@@ -95,9 +110,13 @@ class Pry
|
|
95
110
|
end
|
96
111
|
|
97
112
|
private
|
98
|
-
def
|
99
|
-
@plugins.any? { |
|
113
|
+
def plugin_located?(plugin)
|
114
|
+
@plugins.any? { |existing| existing.gem_name == plugin.gem_name }
|
100
115
|
end
|
101
|
-
end
|
102
116
|
|
117
|
+
def gem_list
|
118
|
+
Gem.refresh
|
119
|
+
Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')
|
120
|
+
end
|
121
|
+
end
|
103
122
|
end
|