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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +251 -16
  3. data/LICENSE +1 -1
  4. data/README.md +35 -51
  5. data/bin/pry +3 -11
  6. data/lib/pry/basic_object.rb +6 -0
  7. data/lib/pry/cli.rb +50 -52
  8. data/lib/pry/code/code_file.rb +13 -6
  9. data/lib/pry/code/code_range.rb +3 -3
  10. data/lib/pry/code/loc.rb +14 -8
  11. data/lib/pry/code.rb +12 -5
  12. data/lib/pry/code_object.rb +27 -4
  13. data/lib/pry/color_printer.rb +20 -10
  14. data/lib/pry/command.rb +76 -45
  15. data/lib/pry/command_set.rb +17 -45
  16. data/lib/pry/commands/amend_line.rb +3 -4
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat/exception_formatter.rb +10 -8
  19. data/lib/pry/commands/cat/file_formatter.rb +7 -3
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/cat.rb +7 -6
  22. data/lib/pry/commands/change_prompt.rb +29 -9
  23. data/lib/pry/commands/clear_screen.rb +14 -0
  24. data/lib/pry/commands/code_collector.rb +25 -23
  25. data/lib/pry/commands/easter_eggs.rb +12 -12
  26. data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
  27. data/lib/pry/commands/edit.rb +15 -10
  28. data/lib/pry/commands/exit.rb +2 -1
  29. data/lib/pry/commands/find_method.rb +12 -14
  30. data/lib/pry/commands/gem_cd.rb +1 -1
  31. data/lib/pry/commands/gem_install.rb +2 -2
  32. data/lib/pry/commands/gem_list.rb +2 -2
  33. data/lib/pry/commands/gem_open.rb +2 -2
  34. data/lib/pry/commands/gem_readme.rb +25 -0
  35. data/lib/pry/commands/gem_search.rb +40 -0
  36. data/lib/pry/commands/gem_stats.rb +83 -0
  37. data/lib/pry/commands/gist.rb +7 -6
  38. data/lib/pry/commands/help.rb +3 -3
  39. data/lib/pry/commands/hist.rb +11 -10
  40. data/lib/pry/commands/import_set.rb +2 -1
  41. data/lib/pry/commands/install_command.rb +7 -6
  42. data/lib/pry/commands/jump_to.rb +7 -7
  43. data/lib/pry/commands/list_inspectors.rb +2 -2
  44. data/lib/pry/commands/ls/constants.rb +14 -3
  45. data/lib/pry/commands/ls/formatter.rb +4 -2
  46. data/lib/pry/commands/ls/globals.rb +0 -2
  47. data/lib/pry/commands/ls/grep.rb +0 -2
  48. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  49. data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
  50. data/lib/pry/commands/ls/local_names.rb +0 -2
  51. data/lib/pry/commands/ls/local_vars.rb +0 -2
  52. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  53. data/lib/pry/commands/ls/methods.rb +0 -3
  54. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  55. data/lib/pry/commands/ls/self_methods.rb +2 -1
  56. data/lib/pry/commands/ls.rb +30 -31
  57. data/lib/pry/commands/play.rb +3 -4
  58. data/lib/pry/commands/pry_backtrace.rb +1 -1
  59. data/lib/pry/commands/raise_up.rb +2 -1
  60. data/lib/pry/commands/reload_code.rb +2 -2
  61. data/lib/pry/commands/ri.rb +9 -4
  62. data/lib/pry/commands/shell_command.rb +36 -9
  63. data/lib/pry/commands/shell_mode.rb +6 -6
  64. data/lib/pry/commands/show_doc.rb +5 -7
  65. data/lib/pry/commands/show_info.rb +41 -20
  66. data/lib/pry/commands/show_source.rb +5 -2
  67. data/lib/pry/commands/stat.rb +1 -1
  68. data/lib/pry/commands/watch_expression/expression.rb +1 -1
  69. data/lib/pry/commands/watch_expression.rb +9 -7
  70. data/lib/pry/commands/whereami.rb +16 -9
  71. data/lib/pry/commands/wtf.rb +15 -2
  72. data/lib/pry/config/behavior.rb +230 -114
  73. data/lib/pry/config/convenience.rb +24 -21
  74. data/lib/pry/config/default.rb +151 -153
  75. data/lib/pry/config/memoization.rb +48 -0
  76. data/lib/pry/config.rb +30 -19
  77. data/lib/pry/core_extensions.rb +15 -4
  78. data/lib/pry/editor.rb +5 -12
  79. data/lib/pry/exceptions.rb +1 -3
  80. data/lib/pry/forwardable.rb +23 -0
  81. data/lib/pry/helpers/base_helpers.rb +197 -110
  82. data/lib/pry/helpers/command_helpers.rb +5 -4
  83. data/lib/pry/helpers/documentation_helpers.rb +3 -2
  84. data/lib/pry/helpers/options_helpers.rb +6 -6
  85. data/lib/pry/helpers/platform.rb +58 -0
  86. data/lib/pry/helpers/table.rb +20 -15
  87. data/lib/pry/helpers/text.rb +82 -74
  88. data/lib/pry/helpers.rb +1 -0
  89. data/lib/pry/history.rb +44 -10
  90. data/lib/pry/hooks.rb +50 -109
  91. data/lib/pry/indent.rb +21 -19
  92. data/lib/pry/input_completer.rb +146 -123
  93. data/lib/pry/input_lock.rb +0 -2
  94. data/lib/pry/last_exception.rb +2 -2
  95. data/lib/pry/method/disowned.rb +3 -1
  96. data/lib/pry/method/patcher.rb +2 -5
  97. data/lib/pry/method/weird_method_locator.rb +21 -11
  98. data/lib/pry/method.rb +44 -38
  99. data/lib/pry/object_path.rb +5 -4
  100. data/lib/pry/output.rb +37 -37
  101. data/lib/pry/pager.rb +195 -181
  102. data/lib/pry/platform.rb +91 -0
  103. data/lib/pry/plugins.rb +27 -8
  104. data/lib/pry/prompt.rb +144 -25
  105. data/lib/pry/pry_class.rb +83 -33
  106. data/lib/pry/pry_instance.rb +94 -59
  107. data/lib/pry/repl.rb +70 -11
  108. data/lib/pry/repl_file_loader.rb +2 -3
  109. data/lib/pry/ring.rb +84 -0
  110. data/lib/pry/rubygem.rb +9 -7
  111. data/lib/pry/slop/LICENSE +20 -0
  112. data/lib/pry/slop/commands.rb +195 -0
  113. data/lib/pry/slop/option.rb +206 -0
  114. data/lib/pry/slop.rb +661 -0
  115. data/lib/pry/terminal.rb +18 -6
  116. data/lib/pry/testable/evalable.rb +15 -0
  117. data/lib/pry/testable/mockable.rb +14 -0
  118. data/lib/pry/testable/pry_tester.rb +73 -0
  119. data/lib/pry/testable/utility.rb +26 -0
  120. data/lib/pry/testable/variables.rb +46 -0
  121. data/lib/pry/testable.rb +70 -0
  122. data/lib/pry/version.rb +1 -1
  123. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +9 -14
  124. data/lib/pry/wrapped_module.rb +22 -21
  125. data/lib/pry.rb +21 -50
  126. metadata +35 -46
  127. data/lib/pry/commands/list_prompts.rb +0 -35
  128. data/lib/pry/commands/simple_prompt.rb +0 -22
  129. data/lib/pry/history_array.rb +0 -121
  130. data/lib/pry/rbx_path.rb +0 -22
  131. 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::Pager
7
- class StopPaging < StandardError
8
- end
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
- # Yields a pager object (`NullPager`, `SimplePager`, or `SystemPager`). All
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
- private
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
- # `NullPager` is a "pager" that actually just prints all output as it comes
63
- # in. Used when `Pry.config.pager` is false.
64
- class NullPager
65
- def initialize(out)
66
- @out = out
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
- def puts(str)
70
- print "#{str.chomp}\n"
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
- def print(str)
74
- write str
75
- end
76
- alias << print
41
+ private
77
42
 
78
- def write(str)
79
- @out.write str
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
- def close
83
- end
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
- private
71
+ def puts(str)
72
+ print "#{str.chomp}\n"
73
+ end
86
74
 
87
- def height
88
- @height ||= Pry::Terminal.height!
89
- end
75
+ def print(str)
76
+ write str
77
+ end
78
+ alias << print
90
79
 
91
- def width
92
- @width ||= Pry::Terminal.width!
93
- end
94
- end
80
+ def write(str)
81
+ @out.write str
82
+ end
83
+
84
+ def close
85
+ end
86
+
87
+ private
95
88
 
96
- # `SimplePager` is a straightforward pure-Ruby pager. We use it on JRuby and
97
- # when we can't find a usable external pager.
98
- class SimplePager < NullPager
99
- def initialize(*)
100
- super
101
- @tracker = PageTracker.new(height - 3, width)
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
- def write(str)
105
- str.lines.each do |line|
106
- @out.print line
107
- @tracker.record line
108
-
109
- if @tracker.page?
110
- @out.print "\n"
111
- @out.print "\e[0m"
112
- @out.print "<page break> --- Press enter to continue " \
113
- "( q<enter> to break ) --- <page break>\n"
114
- raise StopPaging if Readline.readline("").chomp == "q"
115
- @tracker.reset
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
- # `SystemPager` buffers output until we're pretty sure it's at least a page
122
- # long, then invokes an external pager and starts streaming output to it. If
123
- # `#close` is called before then, it just prints out the buffered content.
124
- class SystemPager < NullPager
125
- def self.default_pager
126
- pager = ENV["PAGER"] || ""
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
- # Default to less, and make sure less is being passed the correct options
129
- if pager.strip.empty? or pager =~ /^less\b/
130
- pager = "less -R -F -X"
131
- end
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
- pager
134
- end
138
+ pager
139
+ end
135
140
 
136
- def self.available?
137
- if @system_pager.nil?
138
- @system_pager = begin
139
- pager_executable = default_pager.split(' ').first
140
- `which #{pager_executable}`
141
- $?.success?
142
- rescue
143
- false
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
- def initialize(*)
151
- super
152
- @tracker = PageTracker.new(height, width)
153
- @buffer = ""
154
- end
161
+ def initialize(*)
162
+ super
163
+ @tracker = PageTracker.new(height, width)
164
+ @buffer = ""
165
+ @pager = nil
166
+ end
155
167
 
156
- def write(str)
157
- if invoked_pager?
158
- write_to_pager str
159
- else
160
- @tracker.record str
161
- @buffer << str
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
- if @tracker.page?
164
- write_to_pager @buffer
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
- def close
172
- if invoked_pager?
173
- pager.close
174
- else
175
- @out.puts @buffer
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
- private
191
+ private
180
192
 
181
- def write_to_pager(text)
182
- pager.write @out.decolorize_maybe(text)
183
- end
193
+ def write_to_pager(text)
194
+ pager.write @out.decolorize_maybe(text)
195
+ end
184
196
 
185
- def invoked_pager?
186
- @pager
187
- end
197
+ def invoked_pager?
198
+ @pager
199
+ end
188
200
 
189
- def pager
190
- @pager ||= IO.popen(self.class.default_pager, 'w')
201
+ def pager
202
+ @pager ||= IO.popen(self.class.default_pager, 'w')
203
+ end
191
204
  end
192
- end
193
205
 
194
- # `PageTracker` tracks output to determine whether it's likely to take up a
195
- # whole page. This doesn't need to be super precise, but we can use it for
196
- # `SimplePager` and to avoid invoking the system pager unnecessarily.
197
- #
198
- # One simplifying assumption is that we don't need `#page?` to return `true`
199
- # on the basis of an incomplete line. Long lines should be counted as
200
- # multiple lines, but we don't have to transition from `false` to `true`
201
- # until we see a newline.
202
- class PageTracker
203
- def initialize(rows, cols)
204
- @rows, @cols = rows, cols
205
- reset
206
- end
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
- def record(str)
209
- str.lines.each do |line|
210
- if line.end_with? "\n"
211
- @row += ((@col + line_length(line) - 1) / @cols) + 1
212
- @col = 0
213
- else
214
- @col += line_length(line)
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
- def page?
220
- @row >= @rows
221
- end
232
+ def page?
233
+ @row >= @rows
234
+ end
222
235
 
223
- def reset
224
- @row = 0
225
- @col = 0
226
- end
236
+ def reset
237
+ @row = 0
238
+ @col = 0
239
+ end
227
240
 
228
- private
241
+ private
229
242
 
230
- # Approximation of the printable length of a given line, without the
231
- # newline and without ANSI color codes.
232
- def line_length(line)
233
- line.chomp.gsub(/\e\[[\d;]*m/, '').length
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
@@ -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(*args)
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
- require cli_options_file if File.exist?(cli_options_file)
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
- Gem.refresh
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
- @plugins << Plugin.new(plugin_name, gem.name, gem, true) if !gem_located?(gem.name)
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 gem_located?(gem_name)
99
- @plugins.any? { |plugin| plugin.gem_name == gem_name }
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