pry 0.11.1 → 0.12.0

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 (121) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +184 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry/cli.rb +17 -24
  7. data/lib/pry/code/code_file.rb +5 -4
  8. data/lib/pry/code/code_range.rb +3 -3
  9. data/lib/pry/code/loc.rb +14 -8
  10. data/lib/pry/code.rb +6 -6
  11. data/lib/pry/code_object.rb +4 -4
  12. data/lib/pry/color_printer.rb +2 -1
  13. data/lib/pry/command.rb +36 -29
  14. data/lib/pry/command_set.rb +17 -52
  15. data/lib/pry/commands/amend_line.rb +3 -4
  16. data/lib/pry/commands/bang.rb +1 -1
  17. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  18. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  19. data/lib/pry/commands/cat.rb +7 -6
  20. data/lib/pry/commands/change_prompt.rb +29 -9
  21. data/lib/pry/commands/clear_screen.rb +14 -0
  22. data/lib/pry/commands/code_collector.rb +9 -9
  23. data/lib/pry/commands/easter_eggs.rb +3 -3
  24. data/lib/pry/commands/edit.rb +8 -7
  25. data/lib/pry/commands/exit.rb +2 -1
  26. data/lib/pry/commands/find_method.rb +11 -13
  27. data/lib/pry/commands/gem_cd.rb +1 -1
  28. data/lib/pry/commands/gem_install.rb +2 -2
  29. data/lib/pry/commands/gem_list.rb +2 -2
  30. data/lib/pry/commands/gem_open.rb +1 -1
  31. data/lib/pry/commands/gem_search.rb +2 -2
  32. data/lib/pry/commands/gem_stats.rb +83 -0
  33. data/lib/pry/commands/gist.rb +7 -6
  34. data/lib/pry/commands/help.rb +3 -3
  35. data/lib/pry/commands/hist.rb +9 -8
  36. data/lib/pry/commands/import_set.rb +2 -1
  37. data/lib/pry/commands/install_command.rb +7 -6
  38. data/lib/pry/commands/list_inspectors.rb +2 -2
  39. data/lib/pry/commands/ls/constants.rb +4 -4
  40. data/lib/pry/commands/ls/formatter.rb +3 -2
  41. data/lib/pry/commands/ls/globals.rb +0 -2
  42. data/lib/pry/commands/ls/grep.rb +0 -2
  43. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  44. data/lib/pry/commands/ls/local_names.rb +0 -2
  45. data/lib/pry/commands/ls/local_vars.rb +0 -2
  46. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  47. data/lib/pry/commands/ls/methods.rb +0 -3
  48. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  49. data/lib/pry/commands/ls/self_methods.rb +0 -1
  50. data/lib/pry/commands/ls.rb +27 -30
  51. data/lib/pry/commands/play.rb +1 -2
  52. data/lib/pry/commands/pry_backtrace.rb +1 -1
  53. data/lib/pry/commands/raise_up.rb +2 -1
  54. data/lib/pry/commands/ri.rb +5 -4
  55. data/lib/pry/commands/shell_command.rb +3 -2
  56. data/lib/pry/commands/shell_mode.rb +6 -6
  57. data/lib/pry/commands/show_doc.rb +5 -7
  58. data/lib/pry/commands/show_info.rb +25 -18
  59. data/lib/pry/commands/show_source.rb +5 -2
  60. data/lib/pry/commands/stat.rb +1 -1
  61. data/lib/pry/commands/watch_expression.rb +9 -7
  62. data/lib/pry/commands/whereami.rb +5 -5
  63. data/lib/pry/commands/wtf.rb +15 -2
  64. data/lib/pry/config/behavior.rb +229 -204
  65. data/lib/pry/config/convenience.rb +24 -21
  66. data/lib/pry/config/default.rb +153 -143
  67. data/lib/pry/config/memoization.rb +41 -37
  68. data/lib/pry/config.rb +33 -9
  69. data/lib/pry/core_extensions.rb +4 -3
  70. data/lib/pry/editor.rb +5 -12
  71. data/lib/pry/exceptions.rb +0 -2
  72. data/lib/pry/helpers/base_helpers.rb +197 -106
  73. data/lib/pry/helpers/command_helpers.rb +5 -4
  74. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  75. data/lib/pry/helpers/options_helpers.rb +5 -5
  76. data/lib/pry/helpers/platform.rb +58 -0
  77. data/lib/pry/helpers/table.rb +20 -15
  78. data/lib/pry/helpers/text.rb +23 -9
  79. data/lib/pry/helpers.rb +1 -0
  80. data/lib/pry/history.rb +21 -8
  81. data/lib/pry/hooks.rb +3 -3
  82. data/lib/pry/indent.rb +15 -17
  83. data/lib/pry/input_completer.rb +12 -7
  84. data/lib/pry/input_lock.rb +0 -2
  85. data/lib/pry/last_exception.rb +1 -1
  86. data/lib/pry/method/disowned.rb +2 -1
  87. data/lib/pry/method/patcher.rb +2 -2
  88. data/lib/pry/method/weird_method_locator.rb +21 -11
  89. data/lib/pry/method.rb +37 -31
  90. data/lib/pry/object_path.rb +5 -4
  91. data/lib/pry/output.rb +3 -2
  92. data/lib/pry/pager.rb +4 -3
  93. data/lib/pry/platform.rb +91 -0
  94. data/lib/pry/plugins.rb +7 -3
  95. data/lib/pry/prompt.rb +144 -25
  96. data/lib/pry/pry_class.rb +53 -29
  97. data/lib/pry/pry_instance.rb +88 -55
  98. data/lib/pry/repl.rb +33 -4
  99. data/lib/pry/repl_file_loader.rb +1 -2
  100. data/lib/pry/ring.rb +84 -0
  101. data/lib/pry/rubygem.rb +6 -6
  102. data/lib/pry/slop/commands.rb +3 -4
  103. data/lib/pry/slop/option.rb +19 -21
  104. data/lib/pry/slop.rb +17 -17
  105. data/lib/pry/terminal.rb +2 -1
  106. data/lib/pry/testable/evalable.rb +15 -0
  107. data/lib/pry/testable/mockable.rb +14 -0
  108. data/lib/pry/testable/pry_tester.rb +73 -0
  109. data/lib/pry/testable/utility.rb +26 -0
  110. data/lib/pry/testable/variables.rb +46 -0
  111. data/lib/pry/testable.rb +70 -0
  112. data/lib/pry/version.rb +1 -1
  113. data/lib/pry/wrapped_module/candidate.rb +2 -2
  114. data/lib/pry/wrapped_module.rb +15 -15
  115. data/lib/pry.rb +18 -47
  116. metadata +24 -30
  117. data/lib/pry/commands/list_prompts.rb +0 -35
  118. data/lib/pry/commands/simple_prompt.rb +0 -22
  119. data/lib/pry/history_array.rb +0 -121
  120. data/lib/pry/rbx_path.rb +0 -22
  121. data/lib/pry/test/helper.rb +0 -179
@@ -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)
@@ -80,6 +84,7 @@ class Pry
80
84
  def locate_plugins
81
85
  gem_list.each do |gem|
82
86
  next if gem.name !~ PRY_PLUGIN_PREFIX
87
+
83
88
  plugin_name = gem.name.split('-', 2).last
84
89
  plugin = Plugin.new(plugin_name, gem.name, gem, false)
85
90
  @plugins << plugin.tap(&:enable!) if plugin.supported? && !plugin_located?(plugin)
@@ -114,5 +119,4 @@ class Pry
114
119
  Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')
115
120
  end
116
121
  end
117
-
118
122
  end
data/lib/pry/prompt.rb CHANGED
@@ -1,26 +1,145 @@
1
- class Pry::Prompt
2
- MAP = {
3
- "default" => {
4
- value: Pry::DEFAULT_PROMPT,
5
- description: "The default Pry prompt. Includes information about the\n" \
6
- "current expression number, evaluation context, and nesting\n" \
7
- "level, plus a reminder that you're using Pry."
8
- },
9
-
10
- "simple" => {
11
- value: Pry::SIMPLE_PROMPT,
12
- description: "A simple '>>'."
13
- },
14
-
15
- "nav" => {
16
- value: Pry::NAV_PROMPT,
17
- description: "A prompt that displays the binding stack as a path and\n" \
18
- "includes information about _in_ and _out_."
19
- },
20
-
21
- "none" => {
22
- value: Pry::NO_PROMPT,
23
- description: "Wave goodbye to the Pry prompt."
24
- }
25
- }
1
+ class Pry
2
+ # Prompt represents the Pry prompt, which can be used with Readline-like
3
+ # libraries. It defines a few default prompts (default prompt, simple prompt,
4
+ # etc) and also provides an API to add custom prompts.
5
+ #
6
+ # @example
7
+ # Pry::Prompt.add(
8
+ # :ipython,
9
+ # 'IPython-like prompt', [':', '...:']
10
+ # ) do |_context, _nesting, _pry_, sep|
11
+ # sep == ':' ? "In [#{_pry_.input_ring.count}]: " : ' ...: '
12
+ # end
13
+ #
14
+ # # Produces:
15
+ # # In [3]: def foo
16
+ # # ...: puts 'foo'
17
+ # # ...: end
18
+ # # => :foo
19
+ # # In [4]:
20
+ # @since v0.11.0
21
+ # @api public
22
+ module Prompt
23
+ # @return [String]
24
+ DEFAULT_NAME = 'pry'.freeze
25
+
26
+ # @return [Array<Object>] the list of objects that are known to have a
27
+ # 1-line #inspect output suitable for prompt
28
+ SAFE_CONTEXTS = [String, Numeric, Symbol, nil, true, false].freeze
29
+
30
+ # @deprecated Use {Pry::Prompt.add} instead.
31
+ MAP = {}
32
+ deprecate_constant(:MAP) if respond_to?(:deprecate_constant)
33
+
34
+ # A Hash that holds all prompts. The keys of the Hash are prompt
35
+ # names, the values are Hash instances of the format {:description, :value}.
36
+ @prompts = {}
37
+
38
+ class << self
39
+ # Retrieves a prompt.
40
+ #
41
+ # @example
42
+ # Prompt[:my_prompt][:value]
43
+ #
44
+ # @param [Symbol] prompt_name The name of the prompt you want to access
45
+ # @return [Hash{Symbol=>Object}]
46
+ # @since v0.12.0
47
+ def [](prompt_name)
48
+ all[prompt_name.to_s]
49
+ end
50
+
51
+ # @return [Hash{Symbol=>Hash}] the duplicate of the internal prompts hash
52
+ # @note Use this for read-only operations
53
+ # @since v0.12.0
54
+ def all
55
+ @prompts.dup
56
+ end
57
+
58
+ # Adds a new prompt to the prompt hash.
59
+ #
60
+ # @param [Symbol] prompt_name
61
+ # @param [String] description
62
+ # @param [Array<String>] separators The separators to differentiate
63
+ # between prompt modes (default mode and class/method definition mode).
64
+ # The Array *must* have a size of 2.
65
+ # @yield [context, nesting, _pry_, sep]
66
+ # @yieldparam context [Object] the context where Pry is currently in
67
+ # @yieldparam nesting [Integer] whether the context is nested
68
+ # @yieldparam _pry_ [Pry] the Pry instance
69
+ # @yieldparam separator [String] separator string
70
+ # @return [nil]
71
+ # @raise [ArgumentError] if the size of `separators` is not 2
72
+ # @since v0.12.0
73
+ def add(prompt_name, description = '', separators = %w[> *])
74
+ unless separators.size == 2
75
+ raise ArgumentError, "separators size must be 2, given #{separators.size}"
76
+ end
77
+
78
+ @prompts[prompt_name.to_s] = {
79
+ description: description,
80
+ value: separators.map do |sep|
81
+ proc { |context, nesting, _pry_| yield(context, nesting, _pry_, sep) }
82
+ end
83
+ }
84
+
85
+ nil
86
+ end
87
+
88
+ private
89
+
90
+ def prompt_name(name)
91
+ return name unless name.is_a?(Pry::Config::Lazy)
92
+
93
+ name.call
94
+ end
95
+ end
96
+
97
+ add(:default, <<DESC) do |context, nesting, _pry_, sep|
98
+ The default Pry prompt. Includes information about the current expression
99
+ number, evaluation context, and nesting level, plus a reminder that you're
100
+ using Pry.
101
+ DESC
102
+ format(
103
+ "[%<in_count>s] %<name>s(%<context>s)%<nesting>s%<separator>s ",
104
+ in_count: _pry_.input_ring.count,
105
+ name: prompt_name(_pry_.config.prompt_name),
106
+ context: Pry.view_clip(context),
107
+ nesting: (nesting > 0 ? ":#{nesting}" : ''),
108
+ separator: sep
109
+ )
110
+ end
111
+
112
+ add(:simple, "A simple `>>`.\n", ['>> ', ' | ']) do |_, _, _, sep|
113
+ sep
114
+ end
115
+
116
+ add(:nav, <<DESC, %w[> *]) do |context, nesting, _pry_, sep|
117
+ A prompt that displays the binding stack as a path and includes information
118
+ about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.
119
+ DESC
120
+ tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval('self')) }
121
+ format(
122
+ "[%<in_count>s] (%<name>s) %<tree>s: %<stack_size>s%<separator>s ",
123
+ in_count: _pry_.input_ring.count,
124
+ name: prompt_name(_pry_.config.prompt_name),
125
+ tree: tree.join(' / '),
126
+ stack_size: _pry_.binding_stack.size - 1,
127
+ separator: sep
128
+ )
129
+ end
130
+
131
+ add(:shell, <<DESC, %w[$ *]) do |context, nesting, _pry_, sep|
132
+ A prompt that displays `$PWD` as you change it.
133
+ DESC
134
+ format(
135
+ "%<name>s %<context>s:%<pwd>s %<separator>s ",
136
+ name: prompt_name(_pry_.config.prompt_name),
137
+ context: Pry.view_clip(context),
138
+ pwd: Dir.pwd,
139
+ separator: sep
140
+ )
141
+ end
142
+
143
+ add(:none, 'Wave goodbye to the Pry prompt.', Array.new(2)) { '' }
144
+ end
26
145
  end
data/lib/pry/pry_class.rb CHANGED
@@ -1,7 +1,16 @@
1
- require 'pry/config'
2
1
  class Pry
3
-
4
- HOME_RC_FILE = ENV["PRYRC"] || "~/.pryrc"
2
+ HOME_RC_FILE =
3
+ if ENV.key?('PRYRC')
4
+ ENV['PRYRC']
5
+ elsif File.exist?(File.expand_path('~/.pryrc'))
6
+ '~/.pryrc'
7
+ elsif ENV.key?('XDG_CONFIG_HOME') && ENV['XDG_CONFIG_HOME'] != ''
8
+ # See XDG Base Directory Specification at
9
+ # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
10
+ ENV['XDG_CONFIG_HOME'] + '/pry/pryrc'
11
+ else
12
+ '~/.config/pry/pryrc'
13
+ end
5
14
  LOCAL_RC_FILE = "./.pryrc"
6
15
 
7
16
  class << self
@@ -93,9 +102,7 @@ class Pry
93
102
 
94
103
  # Expand a file to its canonical name (following symlinks as appropriate)
95
104
  def self.real_path_to(file)
96
- expanded = Pathname.new(File.expand_path(file)).realpath.to_s
97
- # For rbx 1.9 mode [see rubinius issue #2165]
98
- File.exist?(expanded) ? expanded : nil
105
+ Pathname.new(File.expand_path(file)).realpath.to_s
99
106
  rescue Errno::ENOENT, Errno::EACCES
100
107
  nil
101
108
  end
@@ -110,7 +117,7 @@ class Pry
110
117
  # Trap interrupts on jruby, and make them behave like MRI so we can
111
118
  # catch them.
112
119
  def self.load_traps
113
- trap('INT'){ raise Interrupt }
120
+ trap('INT') { raise Interrupt }
114
121
  end
115
122
 
116
123
  def self.load_win32console
@@ -124,16 +131,16 @@ class Pry
124
131
  For a better Pry experience on Windows, please use ansicon:
125
132
  https://github.com/adoxa/ansicon
126
133
  If you use an alternative to ansicon and don't want to see this warning again,
127
- you can add "Pry.config.windows_console_warning = false" to your .pryrc.
134
+ you can add "Pry.config.windows_console_warning = false" to your pryrc.
128
135
  WARNING
129
136
  end
130
137
  end
131
138
 
132
- # Do basic setup for initial session.
133
- # Including: loading .pryrc, loading plugins, loading requires, and
134
- # loading history.
139
+ # Do basic setup for initial session including: loading pryrc, plugins,
140
+ # requires, and history.
135
141
  def self.initial_session_setup
136
142
  return unless initial_session?
143
+
137
144
  @initial_session = false
138
145
 
139
146
  # note these have to be loaded here rather than in pry_instance as
@@ -143,27 +150,28 @@ you can add "Pry.config.windows_console_warning = false" to your .pryrc.
143
150
 
144
151
  def self.final_session_setup
145
152
  return if @session_finalized
153
+
146
154
  @session_finalized = true
147
155
  load_plugins if Pry.config.should_load_plugins
148
156
  load_requires if Pry.config.should_load_requires
149
157
  load_history if Pry.config.history.should_load
150
158
  load_traps if Pry.config.should_trap_interrupts
151
- load_win32console if Pry::Helpers::BaseHelpers.windows? && !Pry::Helpers::BaseHelpers.windows_ansi?
159
+ load_win32console if Helpers::Platform.windows? && !Helpers::Platform.windows_ansi?
152
160
  end
153
161
 
154
162
  # Start a Pry REPL.
155
- # This method also loads `~/.pryrc` and `./.pryrc` as necessary the
156
- # first time it is invoked.
163
+ # This method also loads `pryrc` as necessary the first time it is invoked.
157
164
  # @param [Object, Binding] target The receiver of the Pry session
158
165
  # @param [Hash] options
159
166
  # @option options (see Pry#initialize)
160
167
  # @example
161
168
  # Pry.start(Object.new, :input => MyInput.new)
162
- def self.start(target=nil, options={})
169
+ def self.start(target = nil, options = {})
163
170
  return if ENV['DISABLE_PRY']
164
171
  if ENV['FAIL_PRY']
165
172
  raise 'You have FAIL_PRY set to true, which results in Pry calls failing'
166
173
  end
174
+
167
175
  options = options.to_hash
168
176
 
169
177
  if in_critical_section?
@@ -231,7 +239,7 @@ you can add "Pry.config.windows_console_warning = false" to your .pryrc.
231
239
  # fixed as of https://github.com/jruby/jruby/commit/d365ebd309cf9df3dde28f5eb36ea97056e0c039
232
240
  # we can drop in the future.
233
241
  obj.to_s
234
- elsif Pry.config.prompt_safe_objects.any? { |v| v === obj } && obj.inspect.length <= max
242
+ elsif Pry.config.prompt_safe_contexts.any? { |v| v === obj } && obj.inspect.length <= max
235
243
  obj.inspect
236
244
  else
237
245
  id == true ? "#<#{obj.class}:0x%x>" % (obj.object_id << 1) : "#<#{obj.class}>"
@@ -267,19 +275,19 @@ you can add "Pry.config.windows_console_warning = false" to your .pryrc.
267
275
  # Pry.run_command "ls -m", :target => Pry
268
276
  # @example Display command output.
269
277
  # Pry.run_command "ls -av", :show_output => true
270
- def self.run_command(command_string, options={})
278
+ def self.run_command(command_string, options = {})
271
279
  options = {
272
- :target => TOPLEVEL_BINDING,
273
- :show_output => true,
274
- :output => Pry.config.output,
275
- :commands => Pry.config.commands
280
+ target: TOPLEVEL_BINDING,
281
+ show_output: true,
282
+ output: Pry.config.output,
283
+ commands: Pry.config.commands
276
284
  }.merge!(options)
277
285
 
278
286
  # :context for compatibility with <= 0.9.11.4
279
287
  target = options[:context] || options[:target]
280
288
  output = options[:show_output] ? options[:output] : StringIO.new
281
289
 
282
- pry = Pry.new(:output => output, :target => target, :commands => options[:commands])
290
+ pry = Pry.new(output: output, target: target, commands: options[:commands])
283
291
  pry.eval command_string
284
292
  nil
285
293
  end
@@ -287,12 +295,10 @@ you can add "Pry.config.windows_console_warning = false" to your .pryrc.
287
295
  def self.default_editor_for_platform
288
296
  return ENV['VISUAL'] if ENV['VISUAL'] and not ENV['VISUAL'].empty?
289
297
  return ENV['EDITOR'] if ENV['EDITOR'] and not ENV['EDITOR'].empty?
290
- if Helpers::BaseHelpers.windows?
291
- 'notepad'
292
- else
293
- %w(editor nano vi).detect do |editor|
294
- system("which #{editor} > /dev/null 2>&1")
295
- end
298
+ return 'notepad' if Helpers::Platform.windows?
299
+
300
+ %w(editor nano vi).detect do |editor|
301
+ system("which #{editor} > /dev/null 2>&1")
296
302
  end
297
303
  end
298
304
 
@@ -389,13 +395,31 @@ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly
389
395
  Thread.current[:pry_critical_section] > 0
390
396
  end
391
397
 
392
- def self.critical_section(&block)
398
+ def self.critical_section
393
399
  Thread.current[:pry_critical_section] ||= 0
394
400
  Thread.current[:pry_critical_section] += 1
395
401
  yield
396
402
  ensure
397
403
  Thread.current[:pry_critical_section] -= 1
398
404
  end
405
+
406
+ # Wraps a block in a named block called `Pry::Config::Lazy`. This is used for
407
+ # dynamic config values, which are calculated every time
408
+ # {Pry::Config::Lazy#call} is called.
409
+ #
410
+ # @example
411
+ # # pryrc
412
+ # Pry.config.prompt_name = Pry.lazy { rand(100) }
413
+ #
414
+ # # Session
415
+ # [1] 96(main)>
416
+ # [2] 19(main)>
417
+ # [3] 80(main)>
418
+ #
419
+ # @return [#call]
420
+ def self.lazy(&block)
421
+ Pry::Config::Lazy.new(&block)
422
+ end
399
423
  end
400
424
 
401
425
  Pry.init