super-smart-mod 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/pry-0.16.0/CHANGELOG.md +1211 -0
- data/pry-0.16.0/LICENSE +25 -0
- data/pry-0.16.0/README.md +469 -0
- data/pry-0.16.0/bin/pry +13 -0
- data/pry-0.16.0/lib/pry/basic_object.rb +10 -0
- data/pry-0.16.0/lib/pry/block_command.rb +22 -0
- data/pry-0.16.0/lib/pry/class_command.rb +194 -0
- data/pry-0.16.0/lib/pry/cli.rb +211 -0
- data/pry-0.16.0/lib/pry/code/code_file.rb +114 -0
- data/pry-0.16.0/lib/pry/code/code_range.rb +73 -0
- data/pry-0.16.0/lib/pry/code/loc.rb +105 -0
- data/pry-0.16.0/lib/pry/code.rb +357 -0
- data/pry-0.16.0/lib/pry/code_object.rb +197 -0
- data/pry-0.16.0/lib/pry/color_printer.rb +66 -0
- data/pry-0.16.0/lib/pry/command.rb +520 -0
- data/pry-0.16.0/lib/pry/command_set.rb +418 -0
- data/pry-0.16.0/lib/pry/command_state.rb +36 -0
- data/pry-0.16.0/lib/pry/commands/amend_line.rb +103 -0
- data/pry-0.16.0/lib/pry/commands/bang.rb +24 -0
- data/pry-0.16.0/lib/pry/commands/bang_pry.rb +21 -0
- data/pry-0.16.0/lib/pry/commands/cat/abstract_formatter.rb +32 -0
- data/pry-0.16.0/lib/pry/commands/cat/exception_formatter.rb +90 -0
- data/pry-0.16.0/lib/pry/commands/cat/file_formatter.rb +77 -0
- data/pry-0.16.0/lib/pry/commands/cat/input_expression_formatter.rb +48 -0
- data/pry-0.16.0/lib/pry/commands/cat.rb +70 -0
- data/pry-0.16.0/lib/pry/commands/cd.rb +48 -0
- data/pry-0.16.0/lib/pry/commands/change_inspector.rb +34 -0
- data/pry-0.16.0/lib/pry/commands/change_prompt.rb +51 -0
- data/pry-0.16.0/lib/pry/commands/clear_screen.rb +20 -0
- data/pry-0.16.0/lib/pry/commands/code_collector.rb +182 -0
- data/pry-0.16.0/lib/pry/commands/disable_pry.rb +31 -0
- data/pry-0.16.0/lib/pry/commands/easter_eggs.rb +101 -0
- data/pry-0.16.0/lib/pry/commands/edit/exception_patcher.rb +29 -0
- data/pry-0.16.0/lib/pry/commands/edit/file_and_line_locator.rb +47 -0
- data/pry-0.16.0/lib/pry/commands/edit.rb +225 -0
- data/pry-0.16.0/lib/pry/commands/exit.rb +47 -0
- data/pry-0.16.0/lib/pry/commands/exit_all.rb +33 -0
- data/pry-0.16.0/lib/pry/commands/exit_program.rb +27 -0
- data/pry-0.16.0/lib/pry/commands/find_method.rb +199 -0
- data/pry-0.16.0/lib/pry/commands/fix_indent.rb +23 -0
- data/pry-0.16.0/lib/pry/commands/help.rb +171 -0
- data/pry-0.16.0/lib/pry/commands/hist.rb +182 -0
- data/pry-0.16.0/lib/pry/commands/import_set.rb +27 -0
- data/pry-0.16.0/lib/pry/commands/jump_to.rb +33 -0
- data/pry-0.16.0/lib/pry/commands/list_inspectors.rb +42 -0
- data/pry-0.16.0/lib/pry/commands/ls/config.rb +54 -0
- data/pry-0.16.0/lib/pry/commands/ls/constants.rb +75 -0
- data/pry-0.16.0/lib/pry/commands/ls/formatter.rb +55 -0
- data/pry-0.16.0/lib/pry/commands/ls/globals.rb +50 -0
- data/pry-0.16.0/lib/pry/commands/ls/grep.rb +23 -0
- data/pry-0.16.0/lib/pry/commands/ls/instance_vars.rb +40 -0
- data/pry-0.16.0/lib/pry/commands/ls/interrogatable.rb +24 -0
- data/pry-0.16.0/lib/pry/commands/ls/jruby_hacks.rb +55 -0
- data/pry-0.16.0/lib/pry/commands/ls/local_names.rb +37 -0
- data/pry-0.16.0/lib/pry/commands/ls/local_vars.rb +47 -0
- data/pry-0.16.0/lib/pry/commands/ls/ls_entity.rb +65 -0
- data/pry-0.16.0/lib/pry/commands/ls/methods.rb +55 -0
- data/pry-0.16.0/lib/pry/commands/ls/methods_helper.rb +50 -0
- data/pry-0.16.0/lib/pry/commands/ls/self_methods.rb +34 -0
- data/pry-0.16.0/lib/pry/commands/ls.rb +114 -0
- data/pry-0.16.0/lib/pry/commands/nesting.rb +29 -0
- data/pry-0.16.0/lib/pry/commands/play.rb +113 -0
- data/pry-0.16.0/lib/pry/commands/pry_backtrace.rb +30 -0
- data/pry-0.16.0/lib/pry/commands/pry_version.rb +21 -0
- data/pry-0.16.0/lib/pry/commands/raise_up.rb +38 -0
- data/pry-0.16.0/lib/pry/commands/reload_code.rb +74 -0
- data/pry-0.16.0/lib/pry/commands/reset.rb +22 -0
- data/pry-0.16.0/lib/pry/commands/ri.rb +75 -0
- data/pry-0.16.0/lib/pry/commands/save_file.rb +63 -0
- data/pry-0.16.0/lib/pry/commands/shell_command.rb +75 -0
- data/pry-0.16.0/lib/pry/commands/shell_mode.rb +30 -0
- data/pry-0.16.0/lib/pry/commands/show_doc.rb +84 -0
- data/pry-0.16.0/lib/pry/commands/show_info.rb +234 -0
- data/pry-0.16.0/lib/pry/commands/show_input.rb +22 -0
- data/pry-0.16.0/lib/pry/commands/show_source.rb +57 -0
- data/pry-0.16.0/lib/pry/commands/stat.rb +44 -0
- data/pry-0.16.0/lib/pry/commands/switch_to.rb +29 -0
- data/pry-0.16.0/lib/pry/commands/toggle_color.rb +28 -0
- data/pry-0.16.0/lib/pry/commands/watch_expression/expression.rb +43 -0
- data/pry-0.16.0/lib/pry/commands/watch_expression.rb +108 -0
- data/pry-0.16.0/lib/pry/commands/whereami.rb +205 -0
- data/pry-0.16.0/lib/pry/commands/wtf.rb +95 -0
- data/pry-0.16.0/lib/pry/config/attributable.rb +22 -0
- data/pry-0.16.0/lib/pry/config/lazy_value.rb +29 -0
- data/pry-0.16.0/lib/pry/config/memoized_value.rb +34 -0
- data/pry-0.16.0/lib/pry/config/value.rb +24 -0
- data/pry-0.16.0/lib/pry/config.rb +321 -0
- data/pry-0.16.0/lib/pry/control_d_handler.rb +28 -0
- data/pry-0.16.0/lib/pry/core_extensions.rb +144 -0
- data/pry-0.16.0/lib/pry/editor.rb +157 -0
- data/pry-0.16.0/lib/pry/env.rb +18 -0
- data/pry-0.16.0/lib/pry/exception_handler.rb +48 -0
- data/pry-0.16.0/lib/pry/exceptions.rb +73 -0
- data/pry-0.16.0/lib/pry/forwardable.rb +27 -0
- data/pry-0.16.0/lib/pry/helpers/base_helpers.rb +71 -0
- data/pry-0.16.0/lib/pry/helpers/command_helpers.rb +146 -0
- data/pry-0.16.0/lib/pry/helpers/documentation_helpers.rb +84 -0
- data/pry-0.16.0/lib/pry/helpers/options_helpers.rb +34 -0
- data/pry-0.16.0/lib/pry/helpers/platform.rb +55 -0
- data/pry-0.16.0/lib/pry/helpers/table.rb +121 -0
- data/pry-0.16.0/lib/pry/helpers/text.rb +118 -0
- data/pry-0.16.0/lib/pry/helpers.rb +8 -0
- data/pry-0.16.0/lib/pry/history.rb +153 -0
- data/pry-0.16.0/lib/pry/hooks.rb +180 -0
- data/pry-0.16.0/lib/pry/indent.rb +414 -0
- data/pry-0.16.0/lib/pry/input/simple_stdio.rb +13 -0
- data/pry-0.16.0/lib/pry/input_completer.rb +283 -0
- data/pry-0.16.0/lib/pry/input_lock.rb +129 -0
- data/pry-0.16.0/lib/pry/inspector.rb +39 -0
- data/pry-0.16.0/lib/pry/last_exception.rb +61 -0
- data/pry-0.16.0/lib/pry/method/disowned.rb +67 -0
- data/pry-0.16.0/lib/pry/method/patcher.rb +131 -0
- data/pry-0.16.0/lib/pry/method/weird_method_locator.rb +222 -0
- data/pry-0.16.0/lib/pry/method.rb +599 -0
- data/pry-0.16.0/lib/pry/object_path.rb +91 -0
- data/pry-0.16.0/lib/pry/output.rb +136 -0
- data/pry-0.16.0/lib/pry/pager.rb +249 -0
- data/pry-0.16.0/lib/pry/prompt.rb +214 -0
- data/pry-0.16.0/lib/pry/pry_class.rb +371 -0
- data/pry-0.16.0/lib/pry/pry_instance.rb +663 -0
- data/pry-0.16.0/lib/pry/repl.rb +326 -0
- data/pry-0.16.0/lib/pry/repl_file_loader.rb +79 -0
- data/pry-0.16.0/lib/pry/ring.rb +89 -0
- data/pry-0.16.0/lib/pry/slop/LICENSE +20 -0
- data/pry-0.16.0/lib/pry/slop/commands.rb +190 -0
- data/pry-0.16.0/lib/pry/slop/option.rb +210 -0
- data/pry-0.16.0/lib/pry/slop.rb +672 -0
- data/pry-0.16.0/lib/pry/syntax_highlighter.rb +26 -0
- data/pry-0.16.0/lib/pry/system_command_handler.rb +17 -0
- data/pry-0.16.0/lib/pry/testable/evalable.rb +24 -0
- data/pry-0.16.0/lib/pry/testable/mockable.rb +22 -0
- data/pry-0.16.0/lib/pry/testable/pry_tester.rb +88 -0
- data/pry-0.16.0/lib/pry/testable/utility.rb +34 -0
- data/pry-0.16.0/lib/pry/testable/variables.rb +52 -0
- data/pry-0.16.0/lib/pry/testable.rb +68 -0
- data/pry-0.16.0/lib/pry/version.rb +5 -0
- data/pry-0.16.0/lib/pry/warning.rb +20 -0
- data/pry-0.16.0/lib/pry/wrapped_module/candidate.rb +145 -0
- data/pry-0.16.0/lib/pry/wrapped_module.rb +382 -0
- data/pry-0.16.0/lib/pry.rb +148 -0
- data/super-smart-mod.gemspec +12 -0
- metadata +182 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
require 'pathname'
|
|
5
|
+
|
|
6
|
+
class Pry
|
|
7
|
+
LOCAL_RC_FILE = "./.pryrc".freeze
|
|
8
|
+
|
|
9
|
+
# @return [Boolean] true if this Ruby supports safe levels and tainting,
|
|
10
|
+
# to guard against using deprecated or unsupported features
|
|
11
|
+
HAS_SAFE_LEVEL = (
|
|
12
|
+
RUBY_ENGINE == 'ruby' &&
|
|
13
|
+
Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
extend Pry::Forwardable
|
|
18
|
+
attr_accessor :custom_completions
|
|
19
|
+
attr_accessor :current_line
|
|
20
|
+
attr_accessor :line_buffer
|
|
21
|
+
attr_accessor :eval_path
|
|
22
|
+
attr_accessor :cli
|
|
23
|
+
attr_accessor :quiet
|
|
24
|
+
attr_accessor :last_internal_error
|
|
25
|
+
attr_accessor :config
|
|
26
|
+
|
|
27
|
+
def_delegators(
|
|
28
|
+
:@config, :input, :input=, :output, :output=, :commands,
|
|
29
|
+
:commands=, :print, :print=, :exception_handler, :exception_handler=,
|
|
30
|
+
:hooks, :hooks=, :color, :color=, :pager, :pager=, :editor, :editor=,
|
|
31
|
+
:memory_size, :memory_size=, :extra_sticky_locals, :extra_sticky_locals=,
|
|
32
|
+
:prompt, :prompt=, :history, :history=
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
#
|
|
36
|
+
# @example
|
|
37
|
+
# Pry.configure do |config|
|
|
38
|
+
# config.eager_load! # optional
|
|
39
|
+
# config.input = # ..
|
|
40
|
+
# config.foo = 2
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# @yield [config]
|
|
44
|
+
# Yields a block with {Pry.config} as its argument.
|
|
45
|
+
#
|
|
46
|
+
def configure
|
|
47
|
+
yield config
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# @return [main]
|
|
53
|
+
# returns the special instance of Object, "main".
|
|
54
|
+
#
|
|
55
|
+
def self.main
|
|
56
|
+
@main ||= TOPLEVEL_BINDING.eval "self"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# @return [Pry::Config]
|
|
61
|
+
# Returns a value store for an instance of Pry running on the current thread.
|
|
62
|
+
#
|
|
63
|
+
def self.current
|
|
64
|
+
Thread.current[:__pry__] ||= {}
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Load the given file in the context of `Pry.toplevel_binding`
|
|
68
|
+
# @param [String] file The unexpanded file path.
|
|
69
|
+
def self.load_file_at_toplevel(file)
|
|
70
|
+
toplevel_binding.eval(File.read(file), file)
|
|
71
|
+
rescue RescuableException => e
|
|
72
|
+
puts "Error loading #{file}: #{e}\n#{e.backtrace.first}"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Load RC files if appropriate This method can also be used to reload the
|
|
76
|
+
# files if they have changed.
|
|
77
|
+
def self.load_rc_files
|
|
78
|
+
rc_files_to_load.each do |file|
|
|
79
|
+
critical_section do
|
|
80
|
+
load_file_at_toplevel(file)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Load the local RC file (./.pryrc)
|
|
86
|
+
def self.rc_files_to_load
|
|
87
|
+
files = []
|
|
88
|
+
files << Pry.config.rc_file if Pry.config.rc_file && Pry.config.should_load_rc
|
|
89
|
+
files << LOCAL_RC_FILE if Pry.config.should_load_local_rc
|
|
90
|
+
files.map { |file| real_path_to(file) }.compact.uniq
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Expand a file to its canonical name (following symlinks as appropriate)
|
|
94
|
+
def self.real_path_to(file)
|
|
95
|
+
Pathname.new(File.expand_path(file)).realpath.to_s
|
|
96
|
+
rescue Errno::ENOENT, Errno::EACCES
|
|
97
|
+
nil
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Load any Ruby files specified with the -r flag on the command line.
|
|
101
|
+
def self.load_requires
|
|
102
|
+
Pry.config.requires.each do |file|
|
|
103
|
+
require file
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Trap interrupts on jruby, and make them behave like MRI so we can
|
|
108
|
+
# catch them.
|
|
109
|
+
def self.load_traps
|
|
110
|
+
trap('INT') { raise Interrupt }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.load_win32console
|
|
114
|
+
require 'win32console'
|
|
115
|
+
# The mswin and mingw versions of pry require win32console, so this should
|
|
116
|
+
# only fail on jruby (where win32console doesn't work).
|
|
117
|
+
# Instead we'll recommend ansicon, which does.
|
|
118
|
+
rescue LoadError
|
|
119
|
+
warn <<-WARNING if Pry.config.windows_console_warning
|
|
120
|
+
For a better Pry experience on Windows, please use ansicon:
|
|
121
|
+
https://github.com/adoxa/ansicon
|
|
122
|
+
If you use an alternative to ansicon and don't want to see this warning again,
|
|
123
|
+
you can add "Pry.config.windows_console_warning = false" to your pryrc.
|
|
124
|
+
WARNING
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Do basic setup for initial session including: loading pryrc, plugins,
|
|
128
|
+
# requires, and history.
|
|
129
|
+
def self.initial_session_setup
|
|
130
|
+
return unless initial_session?
|
|
131
|
+
|
|
132
|
+
@initial_session = false
|
|
133
|
+
|
|
134
|
+
# note these have to be loaded here rather than in _pry_ as
|
|
135
|
+
# we only want them loaded once per entire Pry lifetime.
|
|
136
|
+
load_rc_files
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.final_session_setup
|
|
140
|
+
return if @session_finalized
|
|
141
|
+
|
|
142
|
+
@session_finalized = true
|
|
143
|
+
load_requires if Pry.config.should_load_requires
|
|
144
|
+
load_history if Pry.config.history_load
|
|
145
|
+
load_traps if Pry.config.should_trap_interrupts
|
|
146
|
+
load_win32console if Helpers::Platform.windows? && !Helpers::Platform.windows_ansi?
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Start a Pry REPL.
|
|
150
|
+
# This method also loads `pryrc` as necessary the first time it is invoked.
|
|
151
|
+
# @param [Object, Binding] target The receiver of the Pry session
|
|
152
|
+
# @param [Hash] options
|
|
153
|
+
# @option options (see Pry#initialize)
|
|
154
|
+
# @example
|
|
155
|
+
# Pry.start(Object.new, :input => MyInput.new)
|
|
156
|
+
def self.start(target = nil, options = {})
|
|
157
|
+
return if Pry::Env['DISABLE_PRY']
|
|
158
|
+
if Pry::Env['FAIL_PRY']
|
|
159
|
+
raise 'You have FAIL_PRY set to true, which results in Pry calls failing'
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
options = options.to_hash
|
|
163
|
+
|
|
164
|
+
options[:color] = false if Pry::Env['NO_COLOR']
|
|
165
|
+
|
|
166
|
+
if in_critical_section?
|
|
167
|
+
output.puts "ERROR: Pry started inside Pry."
|
|
168
|
+
output.puts "This can happen if you have a binding.pry inside a #to_s " \
|
|
169
|
+
"or #inspect function."
|
|
170
|
+
return
|
|
171
|
+
end
|
|
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
|
+
|
|
179
|
+
options[:target] = Pry.binding_for(target || toplevel_binding)
|
|
180
|
+
initial_session_setup
|
|
181
|
+
final_session_setup
|
|
182
|
+
|
|
183
|
+
# Unless we were given a backtrace, save the current one
|
|
184
|
+
if options[:backtrace].nil?
|
|
185
|
+
options[:backtrace] = caller
|
|
186
|
+
|
|
187
|
+
# If Pry was started via `binding.pry`, elide that from the backtrace
|
|
188
|
+
if options[:backtrace].first =~ /pry.*core_extensions.*pry/
|
|
189
|
+
options[:backtrace].shift
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
driver = options[:driver] || Pry::REPL
|
|
194
|
+
|
|
195
|
+
# Enter the matrix
|
|
196
|
+
driver.start(options)
|
|
197
|
+
rescue Pry::TooSafeException
|
|
198
|
+
puts "ERROR: Pry cannot work with $SAFE > 0"
|
|
199
|
+
raise
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Execute the file through the REPL loop, non-interactively.
|
|
203
|
+
# @param [String] file_name File name to load through the REPL.
|
|
204
|
+
def self.load_file_through_repl(file_name)
|
|
205
|
+
REPLFileLoader.new(file_name).load
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
#
|
|
209
|
+
# An inspector that clips the output to `max_length` chars.
|
|
210
|
+
# In case of > `max_length` chars the `#<Object...> notation is used.
|
|
211
|
+
#
|
|
212
|
+
# @param [Object] obj
|
|
213
|
+
# The object to view.
|
|
214
|
+
#
|
|
215
|
+
# @param [Hash] options
|
|
216
|
+
# @option options [Integer] :max_length (60)
|
|
217
|
+
# The maximum number of chars before clipping occurs.
|
|
218
|
+
#
|
|
219
|
+
# @option options [Boolean] :id (false)
|
|
220
|
+
# Boolean to indicate whether or not a hex representation of the object ID
|
|
221
|
+
# is attached to the return value when the length of inspect is greater than
|
|
222
|
+
# value of `:max_length`.
|
|
223
|
+
#
|
|
224
|
+
# @return [String]
|
|
225
|
+
# The string representation of `obj`.
|
|
226
|
+
#
|
|
227
|
+
def self.view_clip(obj, options = {})
|
|
228
|
+
max = options.fetch :max_length, 60
|
|
229
|
+
id = options.fetch :id, false
|
|
230
|
+
if obj.is_a?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max
|
|
231
|
+
obj.name.to_s
|
|
232
|
+
elsif Pry.main == obj
|
|
233
|
+
# Special-case to support jruby. Fixed as of:
|
|
234
|
+
# https://github.com/jruby/jruby/commit/d365ebd309cf9df3dde28f5eb36ea97056e0c039
|
|
235
|
+
# we can drop in the future.
|
|
236
|
+
obj.to_s
|
|
237
|
+
# rubocop:disable Style/CaseEquality
|
|
238
|
+
elsif Pry.config.prompt_safe_contexts.any? { |v| v === obj } &&
|
|
239
|
+
obj.inspect.length <= max
|
|
240
|
+
# rubocop:enable Style/CaseEquality
|
|
241
|
+
|
|
242
|
+
obj.inspect
|
|
243
|
+
elsif id
|
|
244
|
+
format("#<#{obj.class}:0x%<id>x>", id: obj.object_id << 1)
|
|
245
|
+
else
|
|
246
|
+
"#<#{obj.class}>"
|
|
247
|
+
end
|
|
248
|
+
rescue RescuableException
|
|
249
|
+
"unknown"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# Load Readline history if required.
|
|
253
|
+
def self.load_history
|
|
254
|
+
Pry.history.load
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# @return [Boolean] Whether this is the first time a Pry session has
|
|
258
|
+
# been started since loading the Pry class.
|
|
259
|
+
def self.initial_session?
|
|
260
|
+
@initial_session
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Run a Pry command from outside a session. The commands available are
|
|
264
|
+
# those referenced by `Pry.config.commands` (the default command set).
|
|
265
|
+
# @param [String] command_string The Pry command (including arguments,
|
|
266
|
+
# if any).
|
|
267
|
+
# @param [Hash] options Optional named parameters.
|
|
268
|
+
# @return [nil]
|
|
269
|
+
# @option options [Object, Binding] :target The object to run the
|
|
270
|
+
# command under. Defaults to `TOPLEVEL_BINDING` (main).
|
|
271
|
+
# @option options [Boolean] :show_output Whether to show command
|
|
272
|
+
# output. Defaults to true.
|
|
273
|
+
# @example Run at top-level with no output.
|
|
274
|
+
# Pry.run_command "ls"
|
|
275
|
+
# @example Run under Pry class, returning only public methods.
|
|
276
|
+
# Pry.run_command "ls -m", :target => Pry
|
|
277
|
+
# @example Display command output.
|
|
278
|
+
# Pry.run_command "ls -av", :show_output => true
|
|
279
|
+
def self.run_command(command_string, options = {})
|
|
280
|
+
options = {
|
|
281
|
+
target: TOPLEVEL_BINDING,
|
|
282
|
+
show_output: true,
|
|
283
|
+
output: Pry.config.output,
|
|
284
|
+
commands: Pry.config.commands
|
|
285
|
+
}.merge!(options)
|
|
286
|
+
|
|
287
|
+
# :context for compatibility with <= 0.9.11.4
|
|
288
|
+
target = options[:context] || options[:target]
|
|
289
|
+
output = options[:show_output] ? options[:output] : StringIO.new
|
|
290
|
+
|
|
291
|
+
pry = Pry.new(output: output, target: target, commands: options[:commands])
|
|
292
|
+
pry.eval command_string
|
|
293
|
+
nil
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def self.auto_resize!
|
|
297
|
+
warn "Pry.auto_resize! was experimental and has been removed."
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# Set all the configurable options back to their default values
|
|
301
|
+
def self.reset_defaults
|
|
302
|
+
@initial_session = true
|
|
303
|
+
@session_finalized = nil
|
|
304
|
+
|
|
305
|
+
self.config = Pry::Config.new
|
|
306
|
+
self.cli = false
|
|
307
|
+
self.current_line = 1
|
|
308
|
+
self.line_buffer = [""]
|
|
309
|
+
self.eval_path = "(pry)"
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# Basic initialization.
|
|
313
|
+
def self.init
|
|
314
|
+
reset_defaults
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# Return a `Binding` object for `target` or return `target` if it is
|
|
318
|
+
# already a `Binding`.
|
|
319
|
+
# In the case where `target` is top-level then return `TOPLEVEL_BINDING`
|
|
320
|
+
# @param [Object] target The object to get a `Binding` object for.
|
|
321
|
+
# @return [Binding] The `Binding` object.
|
|
322
|
+
def self.binding_for(target)
|
|
323
|
+
return target if Binding === target # rubocop:disable Style/CaseEquality
|
|
324
|
+
return TOPLEVEL_BINDING if Pry.main == target
|
|
325
|
+
|
|
326
|
+
target.__binding__
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def self.toplevel_binding
|
|
330
|
+
unless defined?(@toplevel_binding) && @toplevel_binding
|
|
331
|
+
# Grab a copy of the TOPLEVEL_BINDING without any local variables.
|
|
332
|
+
# This binding has a default definee of Object, and new methods are
|
|
333
|
+
# private (just as in TOPLEVEL_BINDING).
|
|
334
|
+
TOPLEVEL_BINDING.eval <<-RUBY
|
|
335
|
+
def self.__pry__
|
|
336
|
+
binding
|
|
337
|
+
end
|
|
338
|
+
Pry.toplevel_binding = __pry__
|
|
339
|
+
class << self; undef __pry__; end
|
|
340
|
+
RUBY
|
|
341
|
+
end
|
|
342
|
+
@toplevel_binding.eval('private')
|
|
343
|
+
@toplevel_binding
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
class << self
|
|
347
|
+
attr_writer :toplevel_binding
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def self.in_critical_section?
|
|
351
|
+
Thread.current[:pry_critical_section] ||= 0
|
|
352
|
+
Thread.current[:pry_critical_section] > 0
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def self.critical_section
|
|
356
|
+
Thread.current[:pry_critical_section] ||= 0
|
|
357
|
+
Thread.current[:pry_critical_section] += 1
|
|
358
|
+
yield
|
|
359
|
+
ensure
|
|
360
|
+
Thread.current[:pry_critical_section] -= 1
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
def self.mutex_available?
|
|
364
|
+
Mutex.new.synchronize { true }
|
|
365
|
+
rescue ThreadError
|
|
366
|
+
false
|
|
367
|
+
end
|
|
368
|
+
private_class_method :mutex_available?
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
Pry.init
|