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,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Ls < Pry::ClassCommand
|
|
6
|
+
match 'ls'
|
|
7
|
+
group 'Context'
|
|
8
|
+
description 'Show the list of vars and methods in the current scope.'
|
|
9
|
+
command_options shellwords: false, interpolate: false
|
|
10
|
+
|
|
11
|
+
banner <<-'BANNER'
|
|
12
|
+
Usage: ls [-m|-M|-p|-pM] [-q|-v] [-c|-i] [Object]
|
|
13
|
+
ls [-g] [-l]
|
|
14
|
+
|
|
15
|
+
ls shows you which methods, constants and variables are accessible to Pry. By
|
|
16
|
+
default it shows you the local variables defined in the current shell, and any
|
|
17
|
+
public methods or instance variables defined on the current object.
|
|
18
|
+
|
|
19
|
+
The colours used are configurable using Pry.config.ls.*_color, and the separator
|
|
20
|
+
is Pry.config.ls.separator.
|
|
21
|
+
|
|
22
|
+
Pry.config.ls.ceiling is used to hide methods defined higher up in the
|
|
23
|
+
inheritance chain, this is by default set to [Object, Module, Class] so that
|
|
24
|
+
methods defined on all Objects are omitted. The -v flag can be used to ignore
|
|
25
|
+
this setting and show all methods, while the -q can be used to set the ceiling
|
|
26
|
+
much lower and show only methods defined on the object or its direct class.
|
|
27
|
+
|
|
28
|
+
Also check out `find-method` command (run `help find-method`).
|
|
29
|
+
BANNER
|
|
30
|
+
|
|
31
|
+
def options(opt)
|
|
32
|
+
opt.on :m, :methods, "Show public methods defined on the Object"
|
|
33
|
+
opt.on :M, "instance-methods", "Show public methods defined in a " \
|
|
34
|
+
"Module or Class"
|
|
35
|
+
opt.on :p, :ppp, "Show public, protected (in yellow) and private " \
|
|
36
|
+
"(in green) methods"
|
|
37
|
+
opt.on :q, :quiet, "Show only methods defined on object.singleton_class " \
|
|
38
|
+
"and object.class"
|
|
39
|
+
opt.on :v, :verbose, "Show methods and constants on all super-classes " \
|
|
40
|
+
"(ignores Pry.config.ls.ceiling)"
|
|
41
|
+
opt.on :g, :globals, "Show global variables, including those builtin to " \
|
|
42
|
+
"Ruby (in cyan)"
|
|
43
|
+
opt.on :l, :locals, "Show hash of local vars, sorted by descending size"
|
|
44
|
+
opt.on :c, :constants, "Show constants, highlighting classes (in blue), " \
|
|
45
|
+
"and exceptions (in purple).\n" \
|
|
46
|
+
"#{' ' * 32}Constants that are pending autoload? " \
|
|
47
|
+
"are also shown (in yellow)"
|
|
48
|
+
opt.on :i, :ivars, "Show instance variables (in blue) and class " \
|
|
49
|
+
"variables (in bright blue)"
|
|
50
|
+
opt.on :G, :grep, "Filter output by regular expression", argument: true
|
|
51
|
+
|
|
52
|
+
if Object.respond_to?(:deprecate_constant)
|
|
53
|
+
opt.on :d, :dconstants, "Show deprecated constants"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
return unless Helpers::Platform.jruby?
|
|
57
|
+
|
|
58
|
+
opt.on :J, "all-java", "Show all the aliases for methods from java " \
|
|
59
|
+
"(default is to show only prettiest)"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Exclude -q, -v and --grep because they,
|
|
63
|
+
# don't specify what the user wants to see.
|
|
64
|
+
def no_user_opts?
|
|
65
|
+
!(opts[:methods] || opts['instance-methods'] || opts[:ppp] ||
|
|
66
|
+
opts[:globals] || opts[:locals] || opts[:constants] || opts[:ivars])
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def process
|
|
70
|
+
@interrogatee = args.empty? ? target_self : target.eval(args.join(' '))
|
|
71
|
+
raise_errors_if_arguments_are_weird
|
|
72
|
+
ls_entity = LsEntity.new(
|
|
73
|
+
interrogatee: @interrogatee,
|
|
74
|
+
no_user_opts: no_user_opts?,
|
|
75
|
+
opts: opts,
|
|
76
|
+
args: args,
|
|
77
|
+
pry_instance: pry_instance
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
pry_instance.pager.page ls_entity.entities_table
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def error_list
|
|
86
|
+
any_args = args.any?
|
|
87
|
+
# rubocop:disable Style/CaseEquality
|
|
88
|
+
non_mod_interrogatee = !(Module === @interrogatee)
|
|
89
|
+
# rubocop:enable Style/CaseEquality
|
|
90
|
+
[
|
|
91
|
+
['-l does not make sense with a specified Object', :locals, any_args],
|
|
92
|
+
['-g does not make sense with a specified Object', :globals, any_args],
|
|
93
|
+
['-q does not make sense with -v', :quiet, opts.present?(:verbose)],
|
|
94
|
+
[
|
|
95
|
+
'-M only makes sense with a Module or a Class', 'instance-methods',
|
|
96
|
+
non_mod_interrogatee
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
'-c only makes sense with a Module or a Class', :constants,
|
|
100
|
+
any_args && non_mod_interrogatee
|
|
101
|
+
]
|
|
102
|
+
]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def raise_errors_if_arguments_are_weird
|
|
106
|
+
error_list.each do |message, option, invalid_expr|
|
|
107
|
+
raise Pry::CommandError, message if opts.present?(option) && invalid_expr
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
Pry::Commands.add_command(Pry::Command::Ls)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Nesting < Pry::ClassCommand
|
|
6
|
+
match 'nesting'
|
|
7
|
+
group 'Navigating Pry'
|
|
8
|
+
description 'Show nesting information.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Show nesting information.
|
|
12
|
+
BANNER
|
|
13
|
+
|
|
14
|
+
def process
|
|
15
|
+
output.puts 'Nesting status:'
|
|
16
|
+
output.puts '--'
|
|
17
|
+
pry_instance.binding_stack.each_with_index do |obj, level|
|
|
18
|
+
if level == 0
|
|
19
|
+
output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)"
|
|
20
|
+
else
|
|
21
|
+
output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Pry::Commands.add_command(Pry::Command::Nesting)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Play < Pry::ClassCommand
|
|
6
|
+
match 'play'
|
|
7
|
+
group 'Editing'
|
|
8
|
+
description 'Playback a string variable, method, line, or file as input.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Usage: play [OPTIONS] [--help]
|
|
12
|
+
|
|
13
|
+
The play command enables you to replay code from files and methods as if they
|
|
14
|
+
were entered directly in the Pry REPL.
|
|
15
|
+
|
|
16
|
+
play --lines 149..153 # assumes current context
|
|
17
|
+
play -i 20 --lines 1..3 # assumes lines of the input expression at 20
|
|
18
|
+
play -o 4 # the output of an expression at 4
|
|
19
|
+
play Pry#repl -l 1..-1 # play the contents of Pry#repl method
|
|
20
|
+
play -e 2 # play from specified line until end of valid expression
|
|
21
|
+
play hello.rb # play a file
|
|
22
|
+
play Rakefile -l 5 # play line 5 of a file
|
|
23
|
+
play -d hi # play documentation of hi method
|
|
24
|
+
play hi --open # play hi method and leave it open
|
|
25
|
+
|
|
26
|
+
https://github.com/pry/pry/wiki/User-Input#wiki-Play
|
|
27
|
+
BANNER
|
|
28
|
+
|
|
29
|
+
def options(opt)
|
|
30
|
+
CodeCollector.inject_options(opt)
|
|
31
|
+
|
|
32
|
+
opt.on :open, 'Plays the selected content except the last line. Useful' \
|
|
33
|
+
' for replaying methods and leaving the method definition' \
|
|
34
|
+
' "open". `amend-line` can then be used to' \
|
|
35
|
+
' modify the method.'
|
|
36
|
+
|
|
37
|
+
opt.on :e, :expression=, 'Executes until end of valid expression', as: Integer
|
|
38
|
+
opt.on :p, :print, 'Prints executed code'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def process
|
|
42
|
+
@cc = CodeCollector.new(args, opts, pry_instance)
|
|
43
|
+
|
|
44
|
+
perform_play
|
|
45
|
+
show_input
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def perform_play
|
|
49
|
+
eval_string << content_after_options
|
|
50
|
+
run "fix-indent"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def show_input
|
|
54
|
+
return unless opts.present?(:print)
|
|
55
|
+
return unless Pry::Code.complete_expression?(eval_string)
|
|
56
|
+
|
|
57
|
+
run 'show-input'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def content_after_options
|
|
61
|
+
if opts.present?(:open)
|
|
62
|
+
restrict_to_lines(content, (0..-2))
|
|
63
|
+
elsif opts.present?(:expression)
|
|
64
|
+
content_at_expression
|
|
65
|
+
else
|
|
66
|
+
content
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def content_at_expression
|
|
71
|
+
code_object.expression_at(opts[:expression])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def code_object
|
|
75
|
+
Pry::Code.new(content)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def should_use_default_file?
|
|
79
|
+
!args.first && !opts.present?(:in) && !opts.present?(:out)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def content
|
|
83
|
+
if should_use_default_file?
|
|
84
|
+
file_content
|
|
85
|
+
else
|
|
86
|
+
@cc.content
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# The file to play from when no code object is specified.
|
|
91
|
+
# e.g `play --lines 4..10`
|
|
92
|
+
def default_file
|
|
93
|
+
file =
|
|
94
|
+
if target.respond_to?(:source_location)
|
|
95
|
+
target.source_location.first
|
|
96
|
+
else
|
|
97
|
+
target.eval("__FILE__")
|
|
98
|
+
end
|
|
99
|
+
file && File.expand_path(file)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def file_content
|
|
103
|
+
if !default_file || !File.exist?(default_file)
|
|
104
|
+
raise CommandError, "File does not exist! File was: #{default_file.inspect}"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
@cc.restrict_to_lines(File.read(default_file), @cc.line_range)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
Pry::Commands.add_command(Pry::Command::Play)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class PryBacktrace < Pry::ClassCommand
|
|
6
|
+
match 'pry-backtrace'
|
|
7
|
+
group 'Context'
|
|
8
|
+
description 'Show the backtrace for the Pry session.'
|
|
9
|
+
|
|
10
|
+
banner <<-BANNER
|
|
11
|
+
Usage: pry-backtrace [OPTIONS] [--help]
|
|
12
|
+
|
|
13
|
+
Show the backtrace for the position in the code where Pry was started. This can
|
|
14
|
+
be used to infer the behavior of the program immediately before it entered Pry,
|
|
15
|
+
just like the backtrace property of an exception.
|
|
16
|
+
|
|
17
|
+
NOTE: if you are looking for the backtrace of the most recent exception raised,
|
|
18
|
+
just type: `_ex_.backtrace` instead.
|
|
19
|
+
See: https://github.com/pry/pry/wiki/Special-Locals
|
|
20
|
+
BANNER
|
|
21
|
+
|
|
22
|
+
def process
|
|
23
|
+
text = "#{bold('Backtrace:')}\n--\n#{pry_instance.backtrace.join("\n")}"
|
|
24
|
+
pry_instance.pager.page(text)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Pry::Commands.add_command(Pry::Command::PryBacktrace)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Version < Pry::ClassCommand
|
|
6
|
+
match 'pry-version'
|
|
7
|
+
group 'Misc'
|
|
8
|
+
description 'Show Pry version.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Show Pry version.
|
|
12
|
+
BANNER
|
|
13
|
+
|
|
14
|
+
def process
|
|
15
|
+
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Pry::Commands.add_command(Pry::Command::Version)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
# N.B. using a regular expression here so that "raise-up 'foo'" does the right thing.
|
|
5
|
+
class Command
|
|
6
|
+
class RaiseUp < Pry::ClassCommand
|
|
7
|
+
match(/raise-up(!?\b.*)/)
|
|
8
|
+
group 'Context'
|
|
9
|
+
description 'Raise an exception out of the current pry instance.'
|
|
10
|
+
command_options listing: 'raise-up'
|
|
11
|
+
|
|
12
|
+
banner <<-BANNER
|
|
13
|
+
Raise up, like exit, allows you to quit pry. Instead of returning a value
|
|
14
|
+
however, it raises an exception. If you don't provide the exception to be
|
|
15
|
+
raised, it will use the most recent exception (in pry `_ex_`).
|
|
16
|
+
|
|
17
|
+
When called as raise-up! (with an exclamation mark), this command raises the
|
|
18
|
+
exception through any nested prys you have created by "cd"ing into objects.
|
|
19
|
+
|
|
20
|
+
raise-up "get-me-out-of-here"
|
|
21
|
+
|
|
22
|
+
# This is equivalent to the command above.
|
|
23
|
+
raise "get-me-out-of-here"
|
|
24
|
+
raise-up
|
|
25
|
+
BANNER
|
|
26
|
+
|
|
27
|
+
def process
|
|
28
|
+
return _pry.pager.page help if captures[0] =~ /(-h|--help)\b/
|
|
29
|
+
|
|
30
|
+
# Handle 'raise-up', 'raise-up "foo"', 'raise-up RuntimeError, 'farble'
|
|
31
|
+
# in a rubyesque manner
|
|
32
|
+
target.eval("pry_instance.raise_up#{captures[0]}")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Pry::Commands.add_command(Pry::Command::RaiseUp)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class ReloadCode < Pry::ClassCommand
|
|
6
|
+
match 'reload-code'
|
|
7
|
+
group 'Misc'
|
|
8
|
+
description 'Reload the source file that contains the specified code object.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Reload the source file that contains the specified code object.
|
|
12
|
+
|
|
13
|
+
e.g reload-code MyClass#my_method #=> reload a method
|
|
14
|
+
reload-code MyClass #=> reload a class
|
|
15
|
+
reload-code my-command #=> reload a pry command
|
|
16
|
+
reload-code self #=> reload the current object
|
|
17
|
+
reload-code #=> reload the current file or object
|
|
18
|
+
BANNER
|
|
19
|
+
|
|
20
|
+
def process
|
|
21
|
+
if !args.empty?
|
|
22
|
+
reload_object(args.join(" "))
|
|
23
|
+
elsif internal_binding?(target)
|
|
24
|
+
reload_object("self")
|
|
25
|
+
else
|
|
26
|
+
reload_current_file
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def current_file
|
|
33
|
+
file =
|
|
34
|
+
if target.respond_to?(:source_location)
|
|
35
|
+
target.source_location.first
|
|
36
|
+
else
|
|
37
|
+
target.eval("__FILE__")
|
|
38
|
+
end
|
|
39
|
+
File.expand_path file
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def reload_current_file
|
|
43
|
+
unless File.exist?(current_file)
|
|
44
|
+
raise CommandError, "Current file: #{current_file} cannot be found on disk!"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
load current_file
|
|
48
|
+
output.puts "The current file: #{current_file} was reloaded!"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def reload_object(identifier)
|
|
52
|
+
code_object = Pry::CodeObject.lookup(identifier, pry_instance)
|
|
53
|
+
check_for_reloadability(code_object, identifier)
|
|
54
|
+
load code_object.source_file
|
|
55
|
+
output.puts "#{identifier} was reloaded!"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def check_for_reloadability(code_object, identifier)
|
|
59
|
+
if !code_object || !code_object.source_file
|
|
60
|
+
raise CommandError, "Cannot locate #{identifier}!"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
return if File.exist?(code_object.source_file)
|
|
64
|
+
|
|
65
|
+
raise CommandError,
|
|
66
|
+
"Cannot reload #{identifier} as it has no associated file on disk. " \
|
|
67
|
+
"File found was: #{code_object.source_file}"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
Pry::Commands.add_command(Pry::Command::ReloadCode)
|
|
72
|
+
Pry::Commands.alias_command 'reload-method', 'reload-code'
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class Reset < Pry::ClassCommand
|
|
6
|
+
match 'reset'
|
|
7
|
+
group 'Context'
|
|
8
|
+
description 'Reset the REPL to a clean state.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Reset the REPL to a clean state.
|
|
12
|
+
BANNER
|
|
13
|
+
|
|
14
|
+
def process
|
|
15
|
+
output.puts 'Pry reset.'
|
|
16
|
+
exec 'pry'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Pry::Commands.add_command(Pry::Command::Reset)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
5
|
+
class Pry
|
|
6
|
+
class Command
|
|
7
|
+
class Ri < Pry::ClassCommand
|
|
8
|
+
match 'ri'
|
|
9
|
+
group 'Introspection'
|
|
10
|
+
description 'View ri documentation.'
|
|
11
|
+
|
|
12
|
+
banner <<-'BANNER'
|
|
13
|
+
Usage: ri [spec]
|
|
14
|
+
|
|
15
|
+
View ri documentation. Relies on the "rdoc" gem being installed.
|
|
16
|
+
See also "show-doc" command.
|
|
17
|
+
|
|
18
|
+
ri Array#each
|
|
19
|
+
BANNER
|
|
20
|
+
|
|
21
|
+
def process(spec)
|
|
22
|
+
unless spec
|
|
23
|
+
return output.puts(
|
|
24
|
+
"Please provide a class, module, or method name (e.g: ri Array#push)"
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Lazily load RI
|
|
29
|
+
require 'rdoc/ri/driver'
|
|
30
|
+
|
|
31
|
+
unless defined? RDoc::RI::PryDriver
|
|
32
|
+
|
|
33
|
+
# Subclass RI so that it formats its output nicely, and uses `lesspipe`.
|
|
34
|
+
subclass = Class.new(RDoc::RI::Driver) # the hard way.
|
|
35
|
+
|
|
36
|
+
subclass.class_eval do
|
|
37
|
+
def initialize(pager, opts)
|
|
38
|
+
@pager = pager
|
|
39
|
+
super opts
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def page
|
|
43
|
+
paging_text = StringIO.new
|
|
44
|
+
yield paging_text
|
|
45
|
+
@pager.page(paging_text.string)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def formatter(_io)
|
|
49
|
+
if @formatter_klass
|
|
50
|
+
@formatter_klass.new
|
|
51
|
+
else
|
|
52
|
+
RDoc::Markup::ToAnsi.new
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
RDoc::RI.const_set :PryDriver, subclass # hook it up!
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Spin-up an RI instance.
|
|
61
|
+
ri = RDoc::RI::PryDriver.new(
|
|
62
|
+
pry_instance.pager, use_stdout: true, interactive: false
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
begin
|
|
66
|
+
ri.display_names [spec] # Get the documentation (finally!)
|
|
67
|
+
rescue RDoc::RI::Driver::NotFoundError => e
|
|
68
|
+
output.puts "error: '#{e.name}' not found"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
Pry::Commands.add_command(Pry::Command::Ri)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class SaveFile < Pry::ClassCommand
|
|
6
|
+
match 'save-file'
|
|
7
|
+
group 'Input and Output'
|
|
8
|
+
description 'Export to a file using content from the REPL.'
|
|
9
|
+
|
|
10
|
+
banner <<-'BANNER'
|
|
11
|
+
Usage: save-file [OPTIONS] --to [FILE]
|
|
12
|
+
|
|
13
|
+
Export to a file using content from the REPL.
|
|
14
|
+
|
|
15
|
+
save-file my_method --to hello.rb
|
|
16
|
+
save-file -i 1..10 --to hello.rb --append
|
|
17
|
+
save-file show-method --to my_command.rb
|
|
18
|
+
save-file sample_file.rb --lines 2..10 --to output_file.rb
|
|
19
|
+
BANNER
|
|
20
|
+
|
|
21
|
+
def options(opt)
|
|
22
|
+
CodeCollector.inject_options(opt)
|
|
23
|
+
|
|
24
|
+
opt.on :to=, "Specify the output file path"
|
|
25
|
+
opt.on :a, :append, "Append output to file"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def process
|
|
29
|
+
@cc = CodeCollector.new(args, opts, pry_instance)
|
|
30
|
+
raise CommandError, "Found no code to save." if @cc.content.empty?
|
|
31
|
+
|
|
32
|
+
if !file_name
|
|
33
|
+
display_content
|
|
34
|
+
else
|
|
35
|
+
save_file
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def file_name
|
|
40
|
+
opts[:to] || nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def save_file
|
|
44
|
+
File.open(file_name, mode) do |f|
|
|
45
|
+
f.puts @cc.content
|
|
46
|
+
end
|
|
47
|
+
output.puts "#{file_name} successfully saved"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def display_content
|
|
51
|
+
output.puts @cc.content
|
|
52
|
+
output.puts "\n\n--\nPlease use `--to FILE` to export to a file."
|
|
53
|
+
output.puts "No file saved!\n--"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def mode
|
|
57
|
+
opts.present?(:append) ? "a" : "w"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Pry::Commands.add_command(Pry::Command::SaveFile)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class ShellCommand < Pry::ClassCommand
|
|
6
|
+
match(/\.(.*)/)
|
|
7
|
+
group 'Input and Output'
|
|
8
|
+
description "All text following a '.' is forwarded to the shell."
|
|
9
|
+
command_options listing: '.<shell command>', use_prefix: false,
|
|
10
|
+
takes_block: true, state: %i[old_pwd]
|
|
11
|
+
|
|
12
|
+
banner <<-'BANNER'
|
|
13
|
+
Usage: .COMMAND_NAME
|
|
14
|
+
|
|
15
|
+
All text following a "." is forwarded to the shell.
|
|
16
|
+
|
|
17
|
+
.ls -aF
|
|
18
|
+
.uname
|
|
19
|
+
BANNER
|
|
20
|
+
|
|
21
|
+
def process(cmd)
|
|
22
|
+
if cmd =~ /^cd\s*(.*)/i
|
|
23
|
+
process_cd parse_destination(Regexp.last_match(1))
|
|
24
|
+
else
|
|
25
|
+
pass_block(cmd)
|
|
26
|
+
if command_block
|
|
27
|
+
command_block.call `#{cmd}`
|
|
28
|
+
else
|
|
29
|
+
pry_instance.config.system.call(output, cmd, pry_instance)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def parse_destination(dest)
|
|
37
|
+
return "~" if dest.empty?
|
|
38
|
+
return dest unless dest == "-"
|
|
39
|
+
|
|
40
|
+
state.old_pwd || raise(CommandError, "No prior directory available")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def process_cd(dest)
|
|
44
|
+
state.old_pwd = Dir.pwd
|
|
45
|
+
Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest))
|
|
46
|
+
rescue Errno::ENOENT
|
|
47
|
+
raise CommandError, "No such directory: #{dest}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def cd_path_env
|
|
51
|
+
Pry::Env['CDPATH']
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def cd_path_exists?
|
|
55
|
+
cd_path_env && cd_path_env.length.nonzero?
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def path_from_cd_path(dest)
|
|
59
|
+
return if !(dest && cd_path_exists?) || special_case_path?(dest)
|
|
60
|
+
|
|
61
|
+
cd_path_env.split(File::PATH_SEPARATOR).each do |path|
|
|
62
|
+
return path if File.directory?(path) && path.split(File::SEPARATOR).last == dest
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def special_case_path?(dest)
|
|
69
|
+
['.', '..', '-'].include?(dest) || dest =~ /\A[#{File::PATH_SEPARATOR}~]/
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
Pry::Commands.add_command(Pry::Command::ShellCommand)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Pry
|
|
4
|
+
class Command
|
|
5
|
+
class ShellMode < Pry::ClassCommand
|
|
6
|
+
match 'shell-mode'
|
|
7
|
+
group 'Input and Output'
|
|
8
|
+
description 'Toggle shell mode. Bring in pwd prompt and file completion.'
|
|
9
|
+
command_options state: %i[disabled prev_prompt]
|
|
10
|
+
|
|
11
|
+
banner <<-'BANNER'
|
|
12
|
+
Toggle shell mode. Bring in pwd prompt and file completion.
|
|
13
|
+
BANNER
|
|
14
|
+
|
|
15
|
+
def process
|
|
16
|
+
state.disabled ^= true
|
|
17
|
+
|
|
18
|
+
if state.disabled
|
|
19
|
+
state.prev_prompt = pry_instance.prompt
|
|
20
|
+
pry_instance.prompt = Pry::Prompt[:shell]
|
|
21
|
+
else
|
|
22
|
+
pry_instance.prompt = state.prev_prompt
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Pry::Commands.add_command(Pry::Command::ShellMode)
|
|
28
|
+
Pry::Commands.alias_command 'file-mode', 'shell-mode'
|
|
29
|
+
end
|
|
30
|
+
end
|