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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a8834347bff9e94179a35d225768c377a94b33750c989983f42c6cd90b9f0a5
4
- data.tar.gz: 363c3c38dea1cba4b0b0b0b0b617b36a91a3d0761c349687deeff54711210886
3
+ metadata.gz: 12ca2e9d51aa715bf4f234dd86bcc55e1f28602e64dc6bc442744d71e6481a13
4
+ data.tar.gz: 447e326878c36eb79eea61bb9ed2f1d36fddb801e5d408fd283c4b7a50d26f76
5
5
  SHA512:
6
- metadata.gz: deda71757450c541d7e0e9981058244817c1ea8ccf9f8ffec81c1d1919bf8bc45493cd392f8ef44baaac4e70e69c4170dd893e3cb5204770494124b033668507
7
- data.tar.gz: bbdeb8c6e1f41f107d49ffd9c042121011870516c0228662e98b905bd41c5714748aa9dd09763a9d8c88a030daa3a317e8121d2882cc97ff72554c09fcee685e
6
+ metadata.gz: cc7b87701a25a3335389254aa3cd1c0f1c2a5edc470e63ba42777cbb1ed6988b4cbc6d78af1b6fa4bd5891f65aed0c00e196e357102780407cb59069dd4aef9c
7
+ data.tar.gz: 7df26040bd5054a7f29e595219d409b82acf311f7d1a0aae87dc7e4a6b73702c9661a9046c18f73c5fdb055962972c6ad8391f00585c58bd96fba59ecea965c1
data/CHANGELOG.md CHANGED
@@ -1,4 +1,118 @@
1
- ### master
1
+ ### [v0.15.2](v0.15.2) (December 24, 2024)
2
+
3
+ #### Bug Fixes
4
+
5
+ * Avoid breaking reading input if Prism version is undetectable
6
+ ([#2340](https://github.com/pry/pry/pull/2340))
7
+
8
+ ### [v0.15.1](v0.15.1) (December 24, 2024)
9
+
10
+ #### Bug Fixes
11
+
12
+ * Restore Pry.config.ls compatibility
13
+ ([#2335](https://github.com/pry/pry/pull/2335))
14
+ * Avoid breaking reading inputs if Prism is not available
15
+ ([#2338](https://github.com/pry/pry/pull/2338))
16
+
17
+ ### [v0.15.0][v0.15.0] (November 15, 2024)
18
+
19
+ #### Features
20
+
21
+ * Added support for Reline
22
+ ([#2298](https://github.com/pry/pry/pull/2298))
23
+ * Added support for Ruby 3.3
24
+ ([#2295](https://github.com/pry/pry/pull/2295))
25
+ * Added Pry::Input::SimpleStdio for dumb terminals when Reline is in use
26
+ ([#2304](https://github.com/pry/pry/pull/2304))
27
+ * Remove OpenStruct usage
28
+ ([#2307](https://github.com/pry/pry/pull/2307))
29
+ ([#2309](https://github.com/pry/pry/pull/2309))
30
+ * Disable coloring of output when NO_COLOR is set.
31
+ ([#2323])(https://github.com/pry/pry/pull/2323))
32
+ * Add `pry --no-multiline` flag to keep single line prompt.
33
+ ([#2327](https://github.com/pry/pry/pull/2327))
34
+
35
+ #### Bug Fixes
36
+
37
+ * Fix typos on docs and and comments
38
+ ([#2300](https://github.com/pry/pry/pull/2300))
39
+ ([#2301](https://github.com/pry/pry/pull/2301))
40
+ * Fix 'calling clear method' on user code when defined in pry context.
41
+ ([#2291](https://github.com/pry/pry/pull/2291))
42
+ * Fix arguments WatchExpression#add_expression
43
+ ([#2278](https://github.com/pry/pry/pull/2278))
44
+
45
+ ### Breaking changes
46
+
47
+ * Remove support for deprecated `Pry.config.prompt = [proc {}, proc {}]`
48
+ Use Pry::Prompt API instead
49
+ ([#2308](https://github.com/pry/pry/pull/2308))
50
+ * Remove deprecated `Pry.config.exception_whitelist`.
51
+ Use `Pry.config.unrescued_exceptions` instead.
52
+ ([#2326](https://github.com/pry/pry/pull/2326))
53
+
54
+ ### [v0.14.2][v0.14.2] (January 9, 2023)
55
+
56
+ #### Features
57
+
58
+ * Configure `code` as a supported editor on Pry::Editor
59
+ ([#2236](https://github.com/pry/pry/pull/2236))
60
+ * Added support for Ruby 3.2
61
+ ([#2263](https://github.com/pry/pry/pull/2263))
62
+ * Added support for Ruby 3.1
63
+ ([#2228](https://github.com/pry/pry/pull/2228))
64
+
65
+ #### Bug fixes
66
+
67
+ * Short circuit eval regexes in finding module definition
68
+ ([#2253](https://github.com/pry/pry/pull/2253))
69
+ * Revert "Escape non-printing characters"
70
+ ([#2235](https://github.com/pry/pry/pull/2235))
71
+ * Fixed bug where WeirdMethodLocator would fail to find the source of a method breaking whereami
72
+ ([#2244](https://github.com/pry/pry/pull/2244))
73
+ * Fixed bug where pry would throw an FrozenError when dealing with incomplete tokens
74
+ ([#2136](https://github.com/pry/pry/pull/2136))
75
+ * Restore --no-history CLI flag functionality
76
+ ([#2196](https://github.com/pry/pry/pull/2196))
77
+ * Fixed bug where reading from the `_out_` sticky local variable could return
78
+ wrong results ([#2201](https://github.com/pry/pry/pull/2201))
79
+
80
+ #### Breaking Changes
81
+
82
+ * Remove support for Ruby 1.9 and JRuby < 9.0
83
+ ([#2239](https://github.com/pry/pry/pull/2239))
84
+
85
+ ### [v0.14.1][v0.14.1] (April 12, 2021)
86
+
87
+ #### Bug fixes
88
+
89
+ * Fixed bad coloring of some RDoc-style docs
90
+ ([#2182](https://github.com/pry/pry/pull/2182))
91
+ * Fixed broken `--plugins` option. It shows a warning now
92
+ ([#2180](https://github.com/pry/pry/pull/2180))
93
+ * Fixed bad output on printing non-visible characters with color codes
94
+ ([#2154](https://github.com/pry/pry/pull/2154))
95
+ * Fixed bad output when colors are disabled and a string with color codes is
96
+ printed ([#2158](https://github.com/pry/pry/pull/2158))
97
+
98
+ ### [v0.14.0][v0.14.0] (February 8, 2021)
99
+
100
+ #### Features
101
+
102
+ * Made `?` an alias to `show-source -d`
103
+ ([#2133](https://github.com/pry/pry/pull/2133))
104
+ * Added support for Ruby 3.0
105
+
106
+ #### Breaking changes
107
+
108
+ * Deleted support for plugin autoloading
109
+ ([#2119](https://github.com/pry/pry/pull/2119)). In order to load a Pry plugin
110
+ you must `require` it from your `pryrc` or add it to your Gemfile.
111
+
112
+ ```rb
113
+ # ~/.pryrc
114
+ require 'pryrc'
115
+ ```
2
116
 
3
117
  ### [v0.13.1][v0.13.1] (April 12, 2020)
4
118
 
@@ -914,7 +1028,7 @@ complete CHANGELOG:
914
1028
  * _pry_ now passed as 3rd parameter to :before_session hook
915
1029
  * ls colors now configurable via Pry.config.ls.local_var_color = :bright_red etc
916
1030
  * ls separator configurable via, e.g Pry.config.ls.separator = " "
917
- * Pry.view_clip() now only calls inspect on a few immediates, otherwise uses the #<> syntax, which has been truncated further to exclude teh mem address, again related to #245
1031
+ * Pry.view_clip() now only calls inspect on a few immediates, otherwise uses the #<> syntax, which has been truncated further to exclude the mem address, again related to #245
918
1032
 
919
1033
  ### 0.9.3 (2011/7/27)
920
1034
  * cat --ex (cats 5 lines above and below line in file where exception was raised)
@@ -1074,3 +1188,5 @@ complete CHANGELOG:
1074
1188
  [v0.12.2]: https://github.com/pry/pry/releases/tag/v0.12.2
1075
1189
  [v0.13.0]: https://github.com/pry/pry/releases/tag/v0.13.0
1076
1190
  [v0.13.1]: https://github.com/pry/pry/releases/tag/v0.13.1
1191
+ [v0.14.0]: https://github.com/pry/pry/releases/tag/v0.14.0
1192
+ [v0.14.1]: https://github.com/pry/pry/releases/tag/v0.14.1
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Pry
2
2
  ===
3
3
 
4
- [![Circle Build Status](https://circleci.com/gh/pry/pry.svg?style=shield)](https://circleci.com/gh/pry/pry)
4
+ [![Pry Build Status](https://github.com/pry/pry/workflows/pry/badge.svg)](https://github.com/pry/pry/actions)
5
5
  [![Code Climate](https://codeclimate.com/github/pry/pry.svg)](https://codeclimate.com/github/pry/pry)
6
6
  [![Gem Version](https://badge.fury.io/rb/pry.svg)](https://badge.fury.io/rb/pry)
7
7
  [![Documentation Status](https://inch-ci.org/github/pry/pry.svg?branch=master)](https://inch-ci.org/github/pry/pry)
@@ -21,7 +21,7 @@ Pry
21
21
 
22
22
  **Links:**
23
23
 
24
- * https://pryrepl.org/
24
+ * https://pry.github.io/
25
25
  * [YARD API documentation](https://www.rubydoc.info/gems/pry)
26
26
  * [Wiki](https://github.com/pry/pry/wiki)
27
27
 
@@ -38,7 +38,6 @@ Table of Contents
38
38
  * [Command Shell Integration](#command-shell-integration)
39
39
  * [Code Browsing](#code-browsing)
40
40
  * [Documentation Browsing](#documentation-browsing)
41
- * [Gist integration](#gist-integration)
42
41
  * [Edit methods](#edit-methods)
43
42
  * [Live Help System](#live-help-system)
44
43
  * [Use Pry as your Rails Console](#use-pry-as-your-rails-console)
@@ -82,7 +81,7 @@ Installation
82
81
  ### Bundler
83
82
 
84
83
  ```ruby
85
- gem 'pry', '~> 0.12.2'
84
+ gem 'pry', '~> 0.15.0'
86
85
  ```
87
86
 
88
87
  ### Manual
@@ -208,7 +207,7 @@ hello world!
208
207
  pry(main)> def a.goodbye
209
208
  pry(main)* puts "goodbye cruel world!"
210
209
  pry(main)* end
211
- => nil
210
+ => :goodbye
212
211
  pry(main)> a.goodbye
213
212
  goodbye cruel world!
214
213
  => nil
@@ -266,23 +265,26 @@ syntax and also simply the name of a method that's in scope. You can optionally
266
265
  pass the `-l` option to `show-source` to include line numbers in the output.
267
266
 
268
267
  In the following example we will enter the `Pry` class, list the instance
269
- methods beginning with 're' and display the source code for the `rep` method:
268
+ methods beginning with 'se' and display the source code for the `set_last_result` method:
270
269
 
271
270
  ```ruby
272
271
  pry(main)> cd Pry
273
- pry(Pry):1> ls -M --grep re
274
- Pry#methods: re readline refresh rep repl repl_epilogue repl_prologue retrieve_line
275
- pry(Pry):1> show-source rep -l
276
-
277
- From: /home/john/ruby/projects/pry/lib/pry/pry_instance.rb:143
272
+ pry(Pry):1> ls -M --grep se
273
+ Pry#methods: raise_up raise_up! raise_up_common reset_eval_string select_prompt set_last_result
274
+ pry(Pry):1> show-source set_last_result -l
275
+
276
+ From: /home/john/ruby/projects/pry/lib/pry/pry_instance.rb:405:
277
+ Owner: Pry
278
+ Visibility: public
279
+ Signature: set_last_result(result, code=?)
278
280
  Number of lines: 6
279
281
 
280
- 143: def rep(target=TOPLEVEL_BINDING)
281
- 144: target = Pry.binding_for(target)
282
- 145: result = re(target)
283
- 146:
284
- 147: show_result(result) if should_print?
285
- 148: end
282
+ 405: def set_last_result(result, code = "")
283
+ 406: @last_result_is_exception = false
284
+ 407: @output_ring << result
285
+ 408:
286
+ 409: self.last_result = result unless code =~ /\A\s*\z/
287
+ 410: end
286
288
  ```
287
289
 
288
290
  Note that we can also view C methods (from Ruby Core) using the
@@ -317,7 +319,7 @@ rb_ary_select(VALUE ary)
317
319
  One use-case for Pry is to explore a program at run-time by `cd`-ing in and out
318
320
  of objects and viewing and invoking methods. In the course of exploring it may
319
321
  be useful to read the documentation for a specific method that you come
320
- across. Like `show-source` the `show-doc` command supports two syntaxes - the
322
+ across. `show-source` command supports two syntaxes - the
321
323
  normal `ri` syntax as well as accepting the name of any method that is currently
322
324
  in scope.
323
325
 
@@ -339,14 +341,26 @@ In our example we will enter the `Gem` class and view the documentation for the
339
341
 
340
342
  ```ruby
341
343
  pry(main)> cd Gem
342
- pry(Gem):1> show-doc try_activate
344
+ pry(Gem):1> show-source try_activate -d
343
345
 
344
- From: /Users/john/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:201
345
- Number of lines: 3
346
+ From: /Users/john/rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems.rb:194:
347
+ Owner: #<Class:Gem>
348
+ Visibility: public
349
+ Signature: try_activate(path)
350
+ Number of lines: 28
346
351
 
347
352
  Try to activate a gem containing path. Returns true if
348
353
  activation succeeded or wasn't needed because it was already
349
354
  activated. Returns false if it can't find the path in a gem.
355
+
356
+ def self.try_activate(path)
357
+ # finds the _latest_ version... regardless of loaded specs and their deps
358
+ # if another gem had a requirement that would mean we shouldn't
359
+ # activate the latest version, then either it would already be activated
360
+ # or if it was ambiguous (and thus unresolved) the code in our custom
361
+ # require will try to activate the more specific version.
362
+
363
+ spec = Gem::Specification.find_by_path path
350
364
  pry(Gem):1>
351
365
  ```
352
366
 
@@ -399,18 +413,21 @@ description if the `--help` option is available.
399
413
 
400
414
  ### Use Pry as your Rails Console
401
415
 
402
- The recommended way to use Pry as your Rails console is to add [the `pry-rails`
403
- gem](https://github.com/rweng/pry-rails) to your Gemfile. This replaces the
404
- default console with Pry, in addition to loading the Rails console helpers and
405
- adding some useful Rails-specific commands.
406
-
407
- If you don't want to change your Gemfile, you can still run a Pry console in
408
- your app's environment using Pry's `-r` flag:
416
+ You can run a Pry console in your app's environment using Pry's `-r` flag:
409
417
 
410
418
  ```sh
411
419
  pry -r ./config/environment
412
420
  ```
413
421
 
422
+ Or start the rails console (`bin/rails console`) and then type `pry`.
423
+
424
+ It's also possible to use Pry as your Rails console by adding [the pry-rails
425
+ gem](https://github.com/pry/pry-rails) to your Gemfile. This replaces the
426
+ default console with Pry, in addition to loading the Rails console helpers and
427
+ adding some useful Rails-specific commands.
428
+
429
+ **Note that `pry-rails` is not currently maintained.**
430
+
414
431
  Also check out the
415
432
  [wiki](https://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry)
416
433
  for more information about integrating Pry with Rails.
@@ -427,8 +444,8 @@ putting the line `Pry.color = false` in your `pryrc` file.
427
444
  Supported Rubies
428
445
  ----------------
429
446
 
430
- * CRuby >= 1.9.3
431
- * JRuby >= 1.7
447
+ * CRuby >= 2.0.0
448
+ * JRuby >= 9.0
432
449
 
433
450
  Contact
434
451
  -------
@@ -2,7 +2,7 @@
2
2
 
3
3
  class Pry
4
4
  class BasicObject < BasicObject
5
- [:Kernel, :File, :Dir, :LoadError, :ENV, :Pry].each do |constant|
5
+ %i[Kernel File Dir LoadError ENV Pry].each do |constant|
6
6
  const_set constant, ::Object.const_get(constant)
7
7
  end
8
8
  include Kernel
@@ -137,7 +137,7 @@ class Pry
137
137
  # end
138
138
  # end
139
139
  #
140
- # @example Define the invokation block anywhere you want
140
+ # @example Define the invocation block anywhere you want
141
141
  # def subcommands(cmd)
142
142
  # cmd.command :download do |opt|
143
143
  # description 'Downloads a content from a server'
@@ -172,7 +172,7 @@ class Pry
172
172
 
173
173
  # The actual body of your command should go here.
174
174
  #
175
- # The `opts` mehod can be called to get the options that Pry::Slop has passed,
175
+ # The `opts` method can be called to get the options that Pry::Slop has passed,
176
176
  # and `args` gives the remaining, unparsed arguments.
177
177
  #
178
178
  # The return value of this method is discarded unless the command was
data/lib/pry/cli.rb CHANGED
@@ -35,13 +35,6 @@ class Pry
35
35
  self
36
36
  end
37
37
 
38
- # Bring in options defined in plugins
39
- def add_plugin_options
40
- Pry.plugins.values.each(&:load_cli_options)
41
-
42
- self
43
- end
44
-
45
38
  # Add a block responsible for processing parsed options.
46
39
  def add_option_processor(&block)
47
40
  self.option_processors ||= []
@@ -124,21 +117,12 @@ class Pry
124
117
  end
125
118
  end
126
119
 
127
- # Bring in options defined by plugins
128
- Pry::Slop.new do
129
- on "no-plugins" do
130
- Pry.config.should_load_plugins = false
131
- end
132
- end.parse(ARGV.dup)
133
-
134
- Pry::CLI.add_plugin_options if Pry.config.should_load_plugins
135
-
136
120
  # The default Pry command line options (before plugin options are included)
137
121
  Pry::CLI.add_options do
138
122
  banner(
139
123
  "Usage: pry [OPTIONS]\n" \
140
124
  "Start a Pry session.\n" \
141
- "See http://pryrepl.org/ for more information.\n" \
125
+ "See http://pry.github.io/ for more information.\n" \
142
126
  "Copyright (c) 2016 John Mair (banisterfiend)" \
143
127
  )
144
128
 
@@ -154,37 +138,37 @@ Pry::CLI.add_options do
154
138
  end
155
139
 
156
140
  on "no-history", "Disable history loading" do
157
- Pry.config.history.should_load = false
141
+ Pry.config.history_load = false
158
142
  end
159
143
 
160
144
  on "no-color", "Disable syntax highlighting for session" do
161
145
  Pry.config.color = false
162
146
  end
163
147
 
148
+ on "no-multiline", "Disables multiline (defaults to true with Reline)" do
149
+ Pry.config.multiline = false
150
+ end
151
+
164
152
  on :f, "Suppress loading of pryrc" do
165
153
  Pry.config.should_load_rc = false
166
154
  Pry.config.should_load_local_rc = false
167
155
  end
168
156
 
169
- on :s, "select-plugin=", "Only load specified plugin (and no others)." do |plugin_name|
170
- Pry.config.should_load_plugins = false
171
- Pry.plugins[plugin_name].activate!
157
+ on :s, "select-plugin=", "Only load specified plugin (and no others)." do |_plugin_name|
158
+ warn "The --select-plugin option is deprecated and has no effect"
172
159
  end
173
160
 
174
- on :d, "disable-plugin=", "Disable a specific plugin." do |plugin_name|
175
- Pry.plugins[plugin_name].disable!
161
+ on :d, "disable-plugin=", "Disable a specific plugin." do |_plugin_name|
162
+ warn "The --disable-plugin option is deprecated and has no effect"
176
163
  end
177
164
 
178
165
  on "no-plugins", "Suppress loading of plugins." do
179
- Pry.config.should_load_plugins = false
166
+ warn "The --no-plugins option is deprecated and has no effect"
180
167
  end
181
168
 
182
169
  on "plugins", "List installed plugins." do
183
- puts "Installed Plugins:"
184
- puts "--"
185
- Pry.locate_plugins.each do |plugin|
186
- puts plugin.name.to_s.ljust(18) << plugin.spec.summary
187
- end
170
+ warn "The --plugins option is deprecated and has no effect"
171
+ warn "Try using `gem list pry-`"
188
172
  Kernel.exit
189
173
  end
190
174
 
data/lib/pry/code.rb CHANGED
@@ -339,21 +339,13 @@ class Pry
339
339
  super
340
340
  end
341
341
  end
342
- undef =~
342
+ undef =~ if method_defined?(:=~)
343
343
 
344
344
  # Check whether String responds to missing methods.
345
345
  def respond_to_missing?(method_name, include_private = false)
346
346
  ''.respond_to?(method_name, include_private) || super
347
347
  end
348
348
 
349
- if RUBY_VERSION.start_with?('1.9')
350
- # @todo This is needed for Ruby 1.9 support where `lines` return an
351
- # Enumerator. Newer Rubies return an Array
352
- def lines
353
- super.to_a
354
- end
355
- end
356
-
357
349
  protected
358
350
 
359
351
  # An abstraction of the `dup.instance_eval` pattern used throughout this
@@ -11,7 +11,7 @@ class Pry
11
11
  # object the user wants (applying precedence rules in doing so -- i.e methods
12
12
  # get precedence over commands with the same name) and 2. Returning
13
13
  # the appropriate object. If the user fails to provide a string
14
- # identifer for the object (i.e they pass in `nil` or "") then the
14
+ # identifier for the object (i.e they pass in `nil` or "") then the
15
15
  # object looked up will be the 'current method' or 'current class'
16
16
  # associated with the Binding.
17
17
  #
@@ -97,7 +97,7 @@ class Pry
97
97
  nil
98
98
  end
99
99
 
100
- # when no paramter is given (i.e CodeObject.lookup(nil)), then we
100
+ # when no parameter is given (i.e CodeObject.lookup(nil)), then we
101
101
  # lookup the 'current object' from the binding.
102
102
  def empty_lookup
103
103
  return nil if str && !str.empty?
data/lib/pry/command.rb CHANGED
@@ -200,7 +200,7 @@ class Pry
200
200
  end
201
201
 
202
202
  def state
203
- Pry::CommandState.default.state_for(match)
203
+ Pry::CommandState.default.state_for(self)
204
204
  end
205
205
  end
206
206
 
@@ -145,7 +145,7 @@ class Pry
145
145
  # Imports all the commands from one or more sets.
146
146
  # @param [Array<CommandSet>] sets Command sets, all of the commands of which
147
147
  # will be imported.
148
- # @return [Pry::CommandSet] Returns the reciever (a command set).
148
+ # @return [Pry::CommandSet] Returns the receiver (a command set).
149
149
  def import(*sets)
150
150
  sets.each do |set|
151
151
  @commands.merge! set.to_hash
@@ -157,7 +157,7 @@ class Pry
157
157
  # Imports some commands from a set
158
158
  # @param [CommandSet] set Set to import commands from
159
159
  # @param [Array<String>] matches Commands to import
160
- # @return [Pry::CommandSet] Returns the reciever (a command set).
160
+ # @return [Pry::CommandSet] Returns the receiver (a command set).
161
161
  def import_from(set, *matches)
162
162
  helper_module.send :include, set.helper_module
163
163
  matches.each do |match|
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ostruct'
4
-
5
3
  class Pry
6
4
  # CommandState is a data structure to hold per-command state.
7
5
  #
@@ -20,12 +18,19 @@ class Pry
20
18
  @command_state = {}
21
19
  end
22
20
 
23
- def state_for(command_name)
24
- @command_state[command_name] ||= OpenStruct.new
21
+ def state_for(command_class)
22
+ @command_state[command_class] ||= command_struct(command_class)
23
+ end
24
+
25
+ def reset(command_class)
26
+ @command_state[command_class] = command_struct(command_class)
25
27
  end
26
28
 
27
- def reset(command_name)
28
- @command_state[command_name] = OpenStruct.new
29
+ private
30
+
31
+ def command_struct(command_class)
32
+ Struct.new(:command, *command_class.command_options[:state])
33
+ .new(command: command_class)
29
34
  end
30
35
  end
31
36
  end
@@ -76,7 +76,7 @@ class Pry
76
76
 
77
77
  # Takes two numbers that are 1-indexed, and returns a range (or
78
78
  # number) that is 0-indexed. 1-indexed means the first element is
79
- # indentified by 1 rather than by 0 (as is the case for Ruby arrays).
79
+ # identified by 1 rather than by 0 (as is the case for Ruby arrays).
80
80
  # @param [Fixnum] start_line_number One-indexed number.
81
81
  # @param [Fixnum] end_line_number One-indexed number.
82
82
  # @return [Range] The zero-indexed range.
@@ -22,6 +22,8 @@ class Pry
22
22
  https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope
23
23
  BANNER
24
24
 
25
+ command_options state: %i[old_stack]
26
+
25
27
  def process
26
28
  state.old_stack ||= []
27
29
 
@@ -22,6 +22,8 @@ class Pry
22
22
  https://github.com/pry/pry/wiki/Editor-integration#wiki-Edit_command
23
23
  BANNER
24
24
 
25
+ command_options state: %i[dynamical_ex_file]
26
+
25
27
  def options(opt)
26
28
  opt.on :e, :ex, "Open the file that raised the most recent exception " \
27
29
  "(_ex_.file)",
@@ -128,7 +128,7 @@ class Pry
128
128
  next if klass.autoload?(name)
129
129
 
130
130
  begin
131
- const = klass.const_get(name)
131
+ const = Pry::Method.singleton_class_of(klass.const_get(name))
132
132
  rescue RescuableException # rubocop:disable Lint/HandleExceptions
133
133
  # constant loading is an inexact science at the best of times,
134
134
  # this often happens when a constant was .autoload? but someone
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ class Pry
6
+ class Command
7
+ class Ls < Pry::ClassCommand
8
+ class Config
9
+ extend Forwardable
10
+
11
+ DEFAULT_OPTIONS = {
12
+ heading_color: :bright_blue,
13
+ public_method_color: :default,
14
+ private_method_color: :blue,
15
+ protected_method_color: :blue,
16
+ method_missing_color: :bright_red,
17
+ local_var_color: :yellow,
18
+ pry_var_color: :default, # e.g. _, pry_instance, _file_
19
+ instance_var_color: :blue, # e.g. @foo
20
+ class_var_color: :bright_blue, # e.g. @@foo
21
+ global_var_color: :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
22
+ builtin_global_color: :cyan, # e.g. $stdin, $-w, $PID
23
+ pseudo_global_color: :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
24
+ constant_color: :default, # e.g. VERSION, ARGF
25
+ class_constant_color: :blue, # e.g. Object, Kernel
26
+ exception_constant_color: :magenta, # e.g. Exception, RuntimeError
27
+ unloaded_constant_color: :yellow, # Constant still in .autoload? state
28
+ separator: " ",
29
+ ceiling: [Object, Module, Class]
30
+ }.freeze
31
+
32
+ DEFAULT_OPTIONS.each_key do |key|
33
+ define_method key do
34
+ @config[key]
35
+ end
36
+
37
+ define_method "#{key}=" do |value|
38
+ @config[key] = value
39
+ end
40
+ end
41
+
42
+ def_delegators :@config, :[], :[]=, :each, :each_pair, :values, :keys, :to_a
43
+
44
+ def initialize(config)
45
+ @config = config
46
+ end
47
+
48
+ def self.default
49
+ new(DEFAULT_OPTIONS.dup)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -4,8 +4,8 @@ class Pry
4
4
  class Command
5
5
  class Ls < Pry::ClassCommand
6
6
  class Constants < Pry::Command::Ls::Formatter
7
- DEPRECATED_CONSTANTS = [
8
- :Data, :Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE
7
+ DEPRECATED_CONSTANTS = %i[
8
+ Data Fixnum Bignum TimeoutError NIL FALSE TRUE
9
9
  ].tap do |constants|
10
10
  constants << :JavaPackageModuleTemplate if Helpers::Platform.jruby?
11
11
  end
@@ -3,27 +3,6 @@
3
3
  class Pry
4
4
  class Command
5
5
  class Ls < Pry::ClassCommand
6
- DEFAULT_OPTIONS = {
7
- heading_color: :bright_blue,
8
- public_method_color: :default,
9
- private_method_color: :blue,
10
- protected_method_color: :blue,
11
- method_missing_color: :bright_red,
12
- local_var_color: :yellow,
13
- pry_var_color: :default, # e.g. _, pry_instance, _file_
14
- instance_var_color: :blue, # e.g. @foo
15
- class_var_color: :bright_blue, # e.g. @@foo
16
- global_var_color: :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
17
- builtin_global_color: :cyan, # e.g. $stdin, $-w, $PID
18
- pseudo_global_color: :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
19
- constant_color: :default, # e.g. VERSION, ARGF
20
- class_constant_color: :blue, # e.g. Object, Kernel
21
- exception_constant_color: :magenta, # e.g. Exception, RuntimeError
22
- unloaded_constant_color: :yellow, # Any constant that is still in .autoload? state
23
- separator: " ",
24
- ceiling: [Object, Module, Class]
25
- }.freeze
26
-
27
6
  match 'ls'
28
7
  group 'Context'
29
8
  description 'Show the list of vars and methods in the current scope.'