pry 0.13.1 → 0.15.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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +118 -2
  3. data/README.md +47 -30
  4. data/lib/pry/basic_object.rb +1 -1
  5. data/lib/pry/class_command.rb +2 -2
  6. data/lib/pry/cli.rb +13 -29
  7. data/lib/pry/code.rb +1 -9
  8. data/lib/pry/code_object.rb +2 -2
  9. data/lib/pry/command.rb +1 -1
  10. data/lib/pry/command_set.rb +2 -2
  11. data/lib/pry/command_state.rb +11 -6
  12. data/lib/pry/commands/amend_line.rb +1 -1
  13. data/lib/pry/commands/cd.rb +2 -0
  14. data/lib/pry/commands/edit.rb +2 -0
  15. data/lib/pry/commands/find_method.rb +1 -1
  16. data/lib/pry/commands/ls/config.rb +54 -0
  17. data/lib/pry/commands/ls/constants.rb +2 -2
  18. data/lib/pry/commands/ls.rb +0 -21
  19. data/lib/pry/commands/raise_up.rb +1 -1
  20. data/lib/pry/commands/ri.rb +1 -1
  21. data/lib/pry/commands/shell_command.rb +1 -1
  22. data/lib/pry/commands/shell_mode.rb +1 -0
  23. data/lib/pry/commands/show_doc.rb +0 -1
  24. data/lib/pry/commands/show_source.rb +1 -0
  25. data/lib/pry/commands/watch_expression/expression.rb +1 -1
  26. data/lib/pry/commands/watch_expression.rb +4 -6
  27. data/lib/pry/config.rb +26 -33
  28. data/lib/pry/control_d_handler.rb +1 -1
  29. data/lib/pry/core_extensions.rb +1 -1
  30. data/lib/pry/editor.rb +3 -1
  31. data/lib/pry/exception_handler.rb +7 -2
  32. data/lib/pry/helpers/command_helpers.rb +1 -1
  33. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  34. data/lib/pry/helpers/platform.rb +1 -6
  35. data/lib/pry/helpers/text.rb +1 -1
  36. data/lib/pry/indent.rb +13 -11
  37. data/lib/pry/input/simple_stdio.rb +13 -0
  38. data/lib/pry/input_completer.rb +2 -2
  39. data/lib/pry/method/patcher.rb +2 -2
  40. data/lib/pry/method/weird_method_locator.rb +2 -2
  41. data/lib/pry/method.rb +4 -4
  42. data/lib/pry/pry_class.rb +17 -7
  43. data/lib/pry/pry_instance.rb +7 -45
  44. data/lib/pry/repl.rb +73 -4
  45. data/lib/pry/ring.rb +2 -2
  46. data/lib/pry/slop.rb +1 -1
  47. data/lib/pry/syntax_highlighter.rb +1 -1
  48. data/lib/pry/version.rb +1 -1
  49. data/lib/pry/warning.rb +3 -10
  50. data/lib/pry/wrapped_module/candidate.rb +9 -8
  51. data/lib/pry/wrapped_module.rb +3 -8
  52. data/lib/pry.rb +3 -1
  53. metadata +9 -8
  54. data/lib/pry/plugins.rb +0 -139
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Pry
4
- # N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing.
4
+ # N.B. using a regular expression here so that "raise-up 'foo'" does the right thing.
5
5
  class Command
6
6
  class RaiseUp < Pry::ClassCommand
7
7
  match(/raise-up(!?\b.*)/)
@@ -57,7 +57,7 @@ class Pry
57
57
  RDoc::RI.const_set :PryDriver, subclass # hook it up!
58
58
  end
59
59
 
60
- # Spin-up an RI insance.
60
+ # Spin-up an RI instance.
61
61
  ri = RDoc::RI::PryDriver.new(
62
62
  pry_instance.pager, use_stdout: true, interactive: false
63
63
  )
@@ -7,7 +7,7 @@ class Pry
7
7
  group 'Input and Output'
8
8
  description "All text following a '.' is forwarded to the shell."
9
9
  command_options listing: '.<shell command>', use_prefix: false,
10
- takes_block: true
10
+ takes_block: true, state: %i[old_pwd]
11
11
 
12
12
  banner <<-'BANNER'
13
13
  Usage: .COMMAND_NAME
@@ -6,6 +6,7 @@ class Pry
6
6
  match 'shell-mode'
7
7
  group 'Input and Output'
8
8
  description 'Toggle shell mode. Bring in pwd prompt and file completion.'
9
+ command_options state: %i[disabled prev_prompt]
9
10
 
10
11
  banner <<-'BANNER'
11
12
  Toggle shell mode. Bring in pwd prompt and file completion.
@@ -89,6 +89,5 @@ class Pry
89
89
  end
90
90
 
91
91
  Pry::Commands.add_command(Pry::Command::ShowDoc)
92
- Pry::Commands.alias_command '?', 'show-doc'
93
92
  end
94
93
  end
@@ -113,5 +113,6 @@ class Pry
113
113
  Pry::Commands.add_command(Pry::Command::ShowSource)
114
114
  Pry::Commands.alias_command 'show-method', 'show-source'
115
115
  Pry::Commands.alias_command '$', 'show-source'
116
+ Pry::Commands.alias_command '?', 'show-source -d'
116
117
  end
117
118
  end
@@ -23,7 +23,7 @@ class Pry
23
23
 
24
24
  # Has the value of the expression changed?
25
25
  #
26
- # We use the pretty-printed string represenation to detect differences
26
+ # We use the pretty-printed string representation to detect differences
27
27
  # as this avoids problems with dup (causes too many differences) and ==
28
28
  # (causes too few)
29
29
  def changed?
@@ -7,7 +7,7 @@ class Pry
7
7
  group 'Context'
8
8
  description 'Watch the value of an expression and print a notification ' \
9
9
  'whenever it changes.'
10
- command_options use_prefix: false
10
+ command_options use_prefix: false, state: %i[watch_expressions]
11
11
 
12
12
  banner <<-'BANNER'
13
13
  Usage: watch [EXPRESSION]
@@ -46,7 +46,7 @@ class Pry
46
46
  list
47
47
  else
48
48
  add_hook
49
- add_expression(args)
49
+ add_expression
50
50
  end
51
51
  end
52
52
 
@@ -88,15 +88,13 @@ class Pry
88
88
  end
89
89
  end
90
90
 
91
- # TODO: fix arguments.
92
- # https://github.com/pry/pry/commit/b031df2f2f5850ee6e9018f33d35f3485a9b0423
93
- def add_expression(_arguments)
91
+ def add_expression
94
92
  expressions << Expression.new(pry_instance, target, arg_string)
95
93
  output.puts "Watching #{Code.new(arg_string).highlighted}"
96
94
  end
97
95
 
98
96
  def add_hook
99
- hook = [:after_eval, :watch_expression]
97
+ hook = %i[after_eval watch_expression]
100
98
  return if pry_instance.hooks.hook_exists?(*hook)
101
99
 
102
100
  pry_instance.hooks.add_hook(*hook) do |_, pry_instance|
data/lib/pry/config.rb CHANGED
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ostruct'
4
-
5
3
  class Pry
6
4
  # @api private
7
5
  class Config
8
6
  extend Attributable
9
7
 
10
- # @return [IO, #readline] he object from which Pry retrieves its lines of
8
+ # @return [IO, #readline] the object from which Pry retrieves its lines of
11
9
  # input
12
10
  attribute :input
13
11
 
@@ -26,10 +24,6 @@ class Pry
26
24
  # @return [Array] Exception that Pry shouldn't rescue
27
25
  attribute :unrescued_exceptions
28
26
 
29
- # @deprecated
30
- # @return [Array] Exception that Pry shouldn't rescue
31
- attribute :exception_whitelist
32
-
33
27
  # @return [Integer] The number of lines of context to show before and after
34
28
  # exceptions
35
29
  attribute :default_window_size
@@ -67,15 +61,15 @@ class Pry
67
61
  # @return [Boolean]
68
62
  attribute :pager
69
63
 
64
+ # @return [Boolean]
65
+ attribute :multiline
66
+
70
67
  # @return [Boolean] whether the global ~/.pryrc should be loaded
71
68
  attribute :should_load_rc
72
69
 
73
70
  # @return [Boolean] whether the local ./.pryrc should be loaded
74
71
  attribute :should_load_local_rc
75
72
 
76
- # @return [Boolean]
77
- attribute :should_load_plugins
78
-
79
73
  # @return [Boolean] whether to load files specified with the -r flag
80
74
  attribute :should_load_requires
81
75
 
@@ -156,7 +150,7 @@ class Pry
156
150
 
157
151
  def initialize
158
152
  merge!(
159
- input: MemoizedValue.new { lazy_readline },
153
+ input: MemoizedValue.new { choose_input },
160
154
  output: $stdout.tap { |out| out.sync = true },
161
155
  commands: Pry::Commands,
162
156
  prompt_name: 'pry',
@@ -170,17 +164,10 @@ class Pry
170
164
  ::SystemExit, ::SignalException, Pry::TooSafeException
171
165
  ],
172
166
 
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
167
  hooks: Pry::Hooks.default,
182
168
  pager: true,
183
169
  system: Pry::SystemCommandHandler.method(:default),
170
+ multiline: true,
184
171
  color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
185
172
  default_window_size: 5,
186
173
  editor: Pry::Editor.default,
@@ -196,14 +183,13 @@ class Pry
196
183
  output_prefix: '=> ',
197
184
  requires: [],
198
185
  should_load_requires: true,
199
- should_load_plugins: true,
200
186
  windows_console_warning: true,
201
187
  control_d_handler: Pry::ControlDHandler.method(:default),
202
188
  memory_size: 100,
203
189
  extra_sticky_locals: {},
204
190
  command_completions: proc { commands.keys },
205
191
  file_completions: proc { Dir['.'] },
206
- ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS),
192
+ ls: Pry::Command::Ls::Config.default,
207
193
  completer: Pry::InputCompleter,
208
194
  history_save: true,
209
195
  history_load: true,
@@ -290,7 +276,17 @@ class Pry
290
276
 
291
277
  private
292
278
 
293
- def lazy_readline
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
294
290
  require 'readline'
295
291
  ::Readline
296
292
  rescue LoadError
@@ -305,17 +301,14 @@ class Pry
305
301
  end
306
302
 
307
303
  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
304
+ [Pry::Env['PRYRC'],
305
+ # See XDG Base Directory Specification at
306
+ # https://specifications.freedesktop.org/basedir-spec/latest/
307
+ "#{Pry::Env['XDG_CONFIG_HOME']}/pry/pryrc",
308
+ File.expand_path('~/.pryrc'),
309
+ File.expand_path('~/.config/pry/pryrc')]
310
+ .compact
311
+ .find { |file| File.exist?(file) }
319
312
  end
320
313
  end
321
314
  end
@@ -19,7 +19,7 @@ class Pry
19
19
  else
20
20
  # Otherwise, saves current binding stack as old stack and pops last
21
21
  # binding out of binding stack (the old stack still has that binding).
22
- cd_state = Pry::CommandState.default.state_for('cd')
22
+ cd_state = Pry::CommandState.default.state_for(Pry::Command::Cd)
23
23
  cd_state.old_stack = pry_instance.binding_stack.dup
24
24
  pry_instance.binding_stack.pop
25
25
  end
@@ -78,7 +78,7 @@ class Object
78
78
  # Module.new.class_eval("binding") has different behaviour than CRuby,
79
79
  # where this is not needed: class_eval("binding") vs class_eval{binding}.
80
80
  # Using a block works around the difference of behaviour on JRuby.
81
- # The scope is clear of local variabless. Don't add any.
81
+ # The scope is clear of local variables. Don't add any.
82
82
  #
83
83
  # This fixes the following two spec failures, at https://travis-ci.org/pry/pry/jobs/274470002
84
84
  # 1) ./spec/pry_spec.rb:360:in `block in (root)'
data/lib/pry/editor.rb CHANGED
@@ -105,7 +105,7 @@ class Pry
105
105
  '--nofork' if blocking
106
106
  when /^jedit/
107
107
  '-wait' if blocking
108
- when /^mate/, /^subl/, /^redcar/
108
+ when /^mate/, /^subl/, /^redcar/, /^code/
109
109
  '-w' if blocking
110
110
  end
111
111
  end
@@ -121,6 +121,8 @@ class Pry
121
121
  "+#{line_number} #{file_name}"
122
122
  when /^mate/, /^geany/
123
123
  "-l #{line_number} #{file_name}"
124
+ when /^code/
125
+ "-g #{file_name}:#{line_number}"
124
126
  when /^subl/
125
127
  "#{file_name}:#{line_number}"
126
128
  when /^uedit32/
@@ -30,8 +30,13 @@ class Pry
30
30
  end
31
31
 
32
32
  def exception_text(exception)
33
- "#{exception.class}: #{exception.message}\n" \
34
- "from #{exception.backtrace.first}\n"
33
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
34
+ "#{exception.class}: #{exception.message}\n" \
35
+ "from #{exception.backtrace.first}\n"
36
+ else
37
+ "#{exception.class}: #{exception.detailed_message}\n" \
38
+ "from #{exception.backtrace.first}\n"
39
+ end
35
40
  end
36
41
 
37
42
  def cause_text(cause)
@@ -70,7 +70,7 @@ class Pry
70
70
 
71
71
  # Find the longest common whitespace to all indented lines. Ignore lines
72
72
  # containing just -- or ++ as these seem to be used by comment authors
73
- # as delimeters.
73
+ # as delimiters.
74
74
  scanned_text = text.scan(/^[ \t]*(?!--\n|\+\+\n)(?=[^ \t\n])/)
75
75
  margin = scanned_text.inject do |current_margin, next_indent|
76
76
  if next_indent.start_with?(current_margin)
@@ -17,12 +17,13 @@ class Pry
17
17
  last_match_ruby = proc do
18
18
  SyntaxHighlighter.highlight(Regexp.last_match(1))
19
19
  end
20
+
20
21
  comment.gsub(%r{<code>(?:\s*\n)?(.*?)\s*</code>}m, &last_match_ruby)
21
22
  .gsub(%r{<em>(?:\s*\n)?(.*?)\s*</em>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
22
23
  .gsub(%r{<i>(?:\s*\n)?(.*?)\s*</i>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
23
24
  .gsub(%r{<tt>(?:\s*\n)?(.*?)\s*</tt>}m, &last_match_ruby)
24
25
  .gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{Regexp.last_match(1)}\e[0m" }
25
- .gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/, &last_match_ruby)
26
+ .gsub(/((?:^[ \t]+(?:(?!.+\e\[)).+(?:\n+|\Z))+)/, &last_match_ruby)
26
27
  .gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{last_match_ruby.call}`" }
27
28
  end
28
29
 
@@ -28,7 +28,7 @@ class Pry
28
28
  def self.windows_ansi?
29
29
  return false unless windows?
30
30
 
31
- !!(defined?(Win32::Console) || Pry::Env['ANSICON'] || mri_2?)
31
+ !!(defined?(Win32::Console) || Pry::Env['ANSICON'] || mri?)
32
32
  end
33
33
 
34
34
  # @return [Boolean]
@@ -46,11 +46,6 @@ class Pry
46
46
  RbConfig::CONFIG['ruby_install_name'] == 'ruby'
47
47
  end
48
48
 
49
- # @return [Boolean]
50
- def self.mri_19?
51
- mri? && RUBY_VERSION.start_with?('1.9')
52
- end
53
-
54
49
  # @return [Boolean]
55
50
  def self.mri_2?
56
51
  mri? && RUBY_VERSION.start_with?('2')
@@ -44,7 +44,7 @@ class Pry
44
44
  # @param [String, #to_s] text
45
45
  # @return [String] _text_ stripped of any color codes.
46
46
  def strip_color(text)
47
- text.to_s.gsub(/(\001)?\e\[.*?(\d)+m(\002)?/, '')
47
+ text.to_s.gsub(/(\001)?(\e\[(\d[;\d]?)*m)(\002)?/, '')
48
48
  end
49
49
 
50
50
  # Returns _text_ as bold text for use on a terminal.
data/lib/pry/indent.rb CHANGED
@@ -17,6 +17,9 @@ class Pry
17
17
  # @return [String] String containing the spaces to be inserted before the next line.
18
18
  attr_reader :indent_level
19
19
 
20
+ # @return [String] String containing the spaces for the current line.
21
+ attr_reader :last_indent_level
22
+
20
23
  # @return [Array<String>] The stack of open tokens.
21
24
  attr_reader :stack
22
25
 
@@ -57,8 +60,8 @@ class Pry
57
60
  #
58
61
  # :pre_constant and :preserved_constant are the CodeRay 0.9.8 and 1.0.0
59
62
  # classifications of "true", "false", and "nil".
60
- IGNORE_TOKENS = [:space, :content, :string, :method, :ident,
61
- :constant, :pre_constant, :predefined_constant].freeze
63
+ IGNORE_TOKENS = %i[space content string method ident
64
+ constant pre_constant predefined_constant].freeze
62
65
 
63
66
  # Tokens that indicate the end of a statement (i.e. that, if they appear
64
67
  # directly before an "if" indicates that that if applies to the same line,
@@ -66,10 +69,10 @@ class Pry
66
69
  #
67
70
  # :reserved and :keywords are the CodeRay 0.9.8 and 1.0.0 respectively
68
71
  # classifications of "super", "next", "return", etc.
69
- STATEMENT_END_TOKENS = IGNORE_TOKENS + [:regexp, :integer, :float,
70
- :keyword, :delimiter, :reserved,
71
- :instance_variable,
72
- :class_variable, :global_variable]
72
+ STATEMENT_END_TOKENS = IGNORE_TOKENS + %i[regexp integer float
73
+ keyword delimiter reserved
74
+ instance_variable
75
+ class_variable global_variable]
73
76
 
74
77
  # Collection of tokens that should appear dedented even though they
75
78
  # don't affect the surrounding code.
@@ -109,7 +112,8 @@ class Pry
109
112
  # reset internal state
110
113
  def reset
111
114
  @stack = []
112
- @indent_level = ''
115
+ @indent_level = String.new # rubocop:disable Style/EmptyLiteral
116
+ @last_indent_level = @indent_level
113
117
  @heredoc_queue = []
114
118
  @close_heredocs = {}
115
119
  @string_start = nil
@@ -164,11 +168,11 @@ class Pry
164
168
 
165
169
  output += line
166
170
 
171
+ @last_indent_level = prefix
167
172
  prefix = new_prefix
168
173
  end
169
174
 
170
175
  @indent_level = prefix
171
-
172
176
  output
173
177
  end
174
178
 
@@ -281,9 +285,7 @@ class Pry
281
285
  # @param [String] string The Ruby to lex
282
286
  # @return [Array] An Array of pairs of [token_value, token_type]
283
287
  def tokenize(string)
284
- tokens = SyntaxHighlighter.tokenize(string)
285
- tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens) # Coderay 1.0.0
286
- tokens.to_a
288
+ SyntaxHighlighter.tokenize(string).each_slice(2).to_a
287
289
  end
288
290
 
289
291
  # Update the internal state about what kind of strings are open.
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Input
5
+ # Readline replacement for low-capability terminals.
6
+ class SimpleStdio
7
+ def self.readline(prompt)
8
+ Pry.config.output.print(prompt)
9
+ $stdin.gets
10
+ end
11
+ end
12
+ end
13
+ end
@@ -234,7 +234,7 @@ class Pry
234
234
  end.compact
235
235
  end
236
236
 
237
- # build_path seperates the input into two parts: path and input.
237
+ # build_path separates the input into two parts: path and input.
238
238
  # input is the partial string that should be completed
239
239
  # path is a proc that takes an input and builds a full path.
240
240
  def build_path(input)
@@ -270,7 +270,7 @@ class Pry
270
270
  end
271
271
 
272
272
  # FIXME: Add Pry here as well?
273
- [:IRB, :SLex, :RubyLex, :RubyToken].each do |module_name|
273
+ %i[IRB SLex RubyLex RubyToken].each do |module_name|
274
274
  next unless Object.const_defined?(module_name)
275
275
 
276
276
  scanner.call(Object.const_get(module_name))
@@ -43,7 +43,7 @@ class Pry
43
43
  #
44
44
  # When we're redefining aliased methods we will overwrite the method at the
45
45
  # unaliased name (so that super continues to work). By wrapping that code in a
46
- # transation we make that not happen, which means that alias_method_chains, etc.
46
+ # translation we make that not happen, which means that alias_method_chains, etc.
47
47
  # continue to work.
48
48
  #
49
49
  def with_method_transaction
@@ -95,7 +95,7 @@ class Pry
95
95
  # Update the source code so that when it has the right owner when eval'd.
96
96
  #
97
97
  # This (combined with definition_for_owner) is backup for the case that
98
- # wrap_for_nesting fails, to ensure that the method will stil be defined in
98
+ # wrap_for_nesting fails, to ensure that the method will still be defined in
99
99
  # the correct place.
100
100
  #
101
101
  # @param [String] source The source to wrap
@@ -123,7 +123,7 @@ class Pry
123
123
  # know which __FILE__ and __LINE__ the binding is at, we can hope to
124
124
  # disambiguate these cases.
125
125
  #
126
- # This obviously won't work if the source is unavaiable for some reason,
126
+ # This obviously won't work if the source is unavailable for some reason,
127
127
  # or if both methods have the same __FILE__ and __LINE__.
128
128
  #
129
129
  # @return [Pry::Method, nil] The Pry::Method representing the
@@ -158,7 +158,7 @@ class Pry
158
158
 
159
159
  alias_name = all_methods_for(target_self).find do |v|
160
160
  location = target_self.method(v).source_location
161
- expanded_source_location(location) == renamed_method_source_location
161
+ location && expanded_source_location(location) == renamed_method_source_location
162
162
  end
163
163
 
164
164
  alias_name && Pry::Method(target_self.method(alias_name))
data/lib/pry/method.rb CHANGED
@@ -530,8 +530,9 @@ class Pry
530
530
  else
531
531
  fail_msg = "Cannot locate this method: #{name}."
532
532
  if Helpers::Platform.mri?
533
- fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get " \
534
- "access to Ruby Core documentation.\n"
533
+ fail_msg += " Run `gem install pry-doc` to install" \
534
+ " Ruby Core documentation," \
535
+ " and `require 'pry-doc'` to load it.\n"
535
536
  end
536
537
  raise CommandError, fail_msg
537
538
  end
@@ -563,8 +564,7 @@ class Pry
563
564
  def method_name_from_first_line(first_ln)
564
565
  return nil if first_ln.strip !~ /^def /
565
566
 
566
- tokens = SyntaxHighlighter.tokenize(first_ln)
567
- tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens)
567
+ tokens = SyntaxHighlighter.tokenize(first_ln).each_slice(2)
568
568
  tokens.each_cons(2) do |t1, t2|
569
569
  if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
570
570
  return t2.first
data/lib/pry/pry_class.rb CHANGED
@@ -24,8 +24,6 @@ class Pry
24
24
  attr_accessor :last_internal_error
25
25
  attr_accessor :config
26
26
 
27
- def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
28
-
29
27
  def_delegators(
30
28
  :@config, :input, :input=, :output, :output=, :commands,
31
29
  :commands=, :print, :print=, :exception_handler, :exception_handler=,
@@ -87,7 +85,7 @@ class Pry
87
85
  # Load the local RC file (./.pryrc)
88
86
  def self.rc_files_to_load
89
87
  files = []
90
- files << Pry.config.rc_file if Pry.config.should_load_rc
88
+ files << Pry.config.rc_file if Pry.config.rc_file && Pry.config.should_load_rc
91
89
  files << LOCAL_RC_FILE if Pry.config.should_load_local_rc
92
90
  files.map { |file| real_path_to(file) }.compact.uniq
93
91
  end
@@ -142,7 +140,6 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
142
140
  return if @session_finalized
143
141
 
144
142
  @session_finalized = true
145
- load_plugins if Pry.config.should_load_plugins
146
143
  load_requires if Pry.config.should_load_requires
147
144
  load_history if Pry.config.history_load
148
145
  load_traps if Pry.config.should_trap_interrupts
@@ -164,6 +161,8 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
164
161
 
165
162
  options = options.to_hash
166
163
 
164
+ options[:color] = false if Pry::Env['NO_COLOR']
165
+
167
166
  if in_critical_section?
168
167
  output.puts "ERROR: Pry started inside Pry."
169
168
  output.puts "This can happen if you have a binding.pry inside a #to_s " \
@@ -171,6 +170,12 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
171
170
  return
172
171
  end
173
172
 
173
+ unless mutex_available?
174
+ output.puts "ERROR: Unable to obtain mutex lock."
175
+ output.puts "This can happen if binding.pry is called from a signal handler"
176
+ return
177
+ end
178
+
174
179
  options[:target] = Pry.binding_for(target || toplevel_binding)
175
180
  initial_session_setup
176
181
  final_session_setup
@@ -212,7 +217,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
212
217
  # The maximum number of chars before clipping occurs.
213
218
  #
214
219
  # @option options [Boolean] :id (false)
215
- # Boolean to indicate whether or not a hex reprsentation of the object ID
220
+ # Boolean to indicate whether or not a hex representation of the object ID
216
221
  # is attached to the return value when the length of inspect is greater than
217
222
  # value of `:max_length`.
218
223
  #
@@ -333,9 +338,7 @@ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly
333
338
 
334
339
  # Basic initialization.
335
340
  def self.init
336
- @plugin_manager ||= PluginManager.new
337
341
  reset_defaults
338
- locate_plugins
339
342
  end
340
343
 
341
344
  # Return a `Binding` object for `target` or return `target` if it is
@@ -383,6 +386,13 @@ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly
383
386
  ensure
384
387
  Thread.current[:pry_critical_section] -= 1
385
388
  end
389
+
390
+ def self.mutex_available?
391
+ Mutex.new.synchronize { true }
392
+ rescue ThreadError
393
+ false
394
+ end
395
+ private_class_method :mutex_available?
386
396
  end
387
397
 
388
398
  Pry.init