pry 0.10.0.pre4-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +25 -0
- data/README.md +406 -0
- data/bin/pry +16 -0
- data/lib/pry.rb +161 -0
- data/lib/pry/cli.rb +220 -0
- data/lib/pry/code.rb +341 -0
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +692 -0
- data/lib/pry/command_set.rb +443 -0
- data/lib/pry/commands.rb +6 -0
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +23 -0
- data/lib/pry/commands/find_method.rb +193 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +32 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +24 -0
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +131 -0
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +5 -0
- data/lib/pry/helpers/base_helpers.rb +113 -0
- data/lib/pry/helpers/command_helpers.rb +156 -0
- data/lib/pry/helpers/documentation_helpers.rb +75 -0
- data/lib/pry/helpers/options_helpers.rb +27 -0
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +107 -0
- data/lib/pry/history.rb +125 -0
- data/lib/pry/history_array.rb +121 -0
- data/lib/pry/hooks.rb +230 -0
- data/lib/pry/indent.rb +406 -0
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +546 -0
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +136 -0
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +103 -0
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +375 -0
- data/lib/pry/pry_instance.rb +654 -0
- data/lib/pry/rbx_path.rb +22 -0
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +74 -0
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +3 -0
- data/lib/pry/wrapped_module.rb +373 -0
- metadata +248 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ShowInput < Pry::ClassCommand
|
3
|
+
match 'show-input'
|
4
|
+
group 'Editing'
|
5
|
+
description 'Show the contents of the input buffer for the current multi-line expression.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Show the contents of the input buffer for the current multi-line expression.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process
|
12
|
+
output.puts Code.new(eval_string).with_line_numbers
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Pry::Commands.add_command(Pry::Command::ShowInput)
|
17
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'pry/commands/show_info'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Command::ShowSource < Command::ShowInfo
|
5
|
+
match 'show-source'
|
6
|
+
group 'Introspection'
|
7
|
+
description 'Show the source for a method or class.'
|
8
|
+
|
9
|
+
banner <<-'BANNER'
|
10
|
+
Usage: show-source [OPTIONS] [METH|CLASS]
|
11
|
+
Aliases: $, show-method
|
12
|
+
|
13
|
+
Show the source for a method or class. Tries instance methods first and then
|
14
|
+
methods by default.
|
15
|
+
|
16
|
+
show-source hi_method
|
17
|
+
show-source hi_method
|
18
|
+
show-source Pry#rep # source for Pry#rep method
|
19
|
+
show-source Pry # for Pry class
|
20
|
+
show-source Pry -a # for all Pry class definitions (all monkey patches)
|
21
|
+
show-source Pry.foo -e # for class of the return value of expression `Pry.foo`
|
22
|
+
show-source Pry --super # for superclass of Pry (Object class)
|
23
|
+
|
24
|
+
https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method
|
25
|
+
BANNER
|
26
|
+
|
27
|
+
def options(opt)
|
28
|
+
opt.on :e, :eval, "evaluate the command's argument as a ruby expression and show the class its return value"
|
29
|
+
super(opt)
|
30
|
+
end
|
31
|
+
|
32
|
+
def process
|
33
|
+
if opts.present?(:e)
|
34
|
+
obj = target.eval(args.first)
|
35
|
+
self.args = Array.new(1) { Module === obj ? obj.name : obj.class.name }
|
36
|
+
end
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
# The source for code_object prepared for display.
|
41
|
+
def content_for(code_object)
|
42
|
+
Code.new(code_object.source, start_line_for(code_object)).
|
43
|
+
with_line_numbers(use_line_numbers?)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Pry::Commands.add_command(Pry::Command::ShowSource)
|
48
|
+
Pry::Commands.alias_command 'show-method', 'show-source'
|
49
|
+
Pry::Commands.alias_command '$', 'show-source'
|
50
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::SimplePrompt < Pry::ClassCommand
|
3
|
+
match 'simple-prompt'
|
4
|
+
group 'prompts'
|
5
|
+
description 'Toggle the simple prompt.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Toggle the simple prompt.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process
|
12
|
+
case _pry_.prompt
|
13
|
+
when Pry::SIMPLE_PROMPT
|
14
|
+
_pry_.pop_prompt
|
15
|
+
else
|
16
|
+
_pry_.push_prompt Pry::SIMPLE_PROMPT
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Pry::Commands.add_command(Pry::Command::SimplePrompt)
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Stat < Pry::ClassCommand
|
3
|
+
match 'stat'
|
4
|
+
group 'Introspection'
|
5
|
+
description 'View method information and set _file_ and _dir_ locals.'
|
6
|
+
command_options :shellwords => false
|
7
|
+
|
8
|
+
banner <<-'BANNER'
|
9
|
+
Usage: stat [OPTIONS] [METH]
|
10
|
+
|
11
|
+
Show method information for method METH and set _file_ and _dir_ locals.
|
12
|
+
|
13
|
+
stat hello_method
|
14
|
+
BANNER
|
15
|
+
|
16
|
+
def options(opt)
|
17
|
+
method_options(opt)
|
18
|
+
end
|
19
|
+
|
20
|
+
def process
|
21
|
+
meth = method_object
|
22
|
+
aliases = meth.aliases
|
23
|
+
|
24
|
+
output.puts unindent <<-EOS
|
25
|
+
Method Information:
|
26
|
+
--
|
27
|
+
Name: #{meth.name}
|
28
|
+
Alias#{ "es" if aliases.length > 1 }: #{ aliases.any? ? aliases.join(", ") : "None." }
|
29
|
+
Owner: #{meth.owner ? meth.owner : "Unknown"}
|
30
|
+
Visibility: #{meth.visibility}
|
31
|
+
Type: #{meth.is_a?(::Method) ? "Bound" : "Unbound"}
|
32
|
+
Arity: #{meth.arity}
|
33
|
+
Method Signature: #{meth.signature}
|
34
|
+
Source Location: #{meth.source_location ? meth.source_location.join(":") : "Not found."}
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Pry::Commands.add_command(Pry::Command::Stat)
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::SwitchTo < Pry::ClassCommand
|
3
|
+
match 'switch-to'
|
4
|
+
group 'Navigating Pry'
|
5
|
+
description 'Start a new subsession on a binding in the current stack.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Start a new subsession on a binding in the current stack (numbered by nesting).
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process(selection)
|
12
|
+
selection = selection.to_i
|
13
|
+
|
14
|
+
if selection < 0 || selection > _pry_.binding_stack.size - 1
|
15
|
+
raise CommandError, "Invalid binding index #{selection} - use `nesting` command to view valid indices."
|
16
|
+
else
|
17
|
+
Pry.start(_pry_.binding_stack[selection])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Pry::Commands.add_command(Pry::Command::SwitchTo)
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ToggleColor < Pry::ClassCommand
|
3
|
+
match 'toggle-color'
|
4
|
+
group 'Misc'
|
5
|
+
description 'Toggle syntax highlighting.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: toggle-color
|
9
|
+
|
10
|
+
Toggle syntax highlighting.
|
11
|
+
BANNER
|
12
|
+
|
13
|
+
def process
|
14
|
+
_pry_.color = color_toggle
|
15
|
+
output.puts "Syntax highlighting #{_pry_.color ? "on" : "off"}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def color_toggle
|
19
|
+
!_pry_.color
|
20
|
+
end
|
21
|
+
|
22
|
+
Pry::Commands.add_command(self)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::WatchExpression < Pry::ClassCommand
|
3
|
+
require 'pry/commands/watch_expression/expression.rb'
|
4
|
+
|
5
|
+
match 'watch'
|
6
|
+
group 'Context'
|
7
|
+
description 'Watch the value of an expression and print a notification whenever it changes.'
|
8
|
+
command_options :use_prefix => false
|
9
|
+
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: watch [EXPRESSION]
|
12
|
+
watch
|
13
|
+
watch --delete [INDEX]
|
14
|
+
|
15
|
+
watch [EXPRESSION] adds an expression to the list of those being watched.
|
16
|
+
It will be re-evaluated every time you hit enter in pry. If its value has
|
17
|
+
changed, the new value will be printed to the console.
|
18
|
+
|
19
|
+
This is useful if you are step-through debugging and want to see how
|
20
|
+
something changes over time. It's also useful if you're trying to write
|
21
|
+
a method inside pry and want to check that it gives the right answers
|
22
|
+
every time you redefine it.
|
23
|
+
|
24
|
+
watch on its own displays all the currently watched expressions and their
|
25
|
+
values, and watch --delete [INDEX] allows you to delete expressions from
|
26
|
+
the list being watched.
|
27
|
+
BANNER
|
28
|
+
|
29
|
+
def options(opt)
|
30
|
+
opt.on :d, :delete,
|
31
|
+
"Delete the watch expression with the given index. If no index is given; clear all watch expressions.",
|
32
|
+
:optional_argument => true, :as => Integer
|
33
|
+
opt.on :l, :list,
|
34
|
+
"Show all current watch expressions and their values. Calling watch with no expressions or options will also show the watch expressions."
|
35
|
+
end
|
36
|
+
|
37
|
+
def process
|
38
|
+
case
|
39
|
+
when opts.present?(:delete)
|
40
|
+
delete opts[:delete]
|
41
|
+
when opts.present?(:list) || args.empty?
|
42
|
+
list
|
43
|
+
else
|
44
|
+
add_hook
|
45
|
+
add_expression(args)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def expressions
|
52
|
+
_pry_.config.watch_expressions ||= []
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete(index)
|
56
|
+
if index
|
57
|
+
output.puts "Deleting watch expression ##{index}: #{expressions[index-1]}"
|
58
|
+
expressions.delete_at(index-1)
|
59
|
+
else
|
60
|
+
output.puts "Deleting all watched expressions"
|
61
|
+
expressions.clear
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def list
|
66
|
+
if expressions.empty?
|
67
|
+
output.puts "No watched expressions"
|
68
|
+
else
|
69
|
+
_pry_.pager.open do |pager|
|
70
|
+
pager.puts "Listing all watched expressions:"
|
71
|
+
pager.puts ""
|
72
|
+
expressions.each_with_index do |expr, index|
|
73
|
+
pager.print text.with_line_numbers(expr.to_s, index+1)
|
74
|
+
end
|
75
|
+
pager.puts ""
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def eval_and_print_changed(output)
|
81
|
+
expressions.each do |expr|
|
82
|
+
expr.eval!
|
83
|
+
if expr.changed?
|
84
|
+
output.puts "#{text.blue "watch"}: #{expr.to_s}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_expression(arguments)
|
90
|
+
expressions << Expression.new(_pry_, target, arg_string)
|
91
|
+
output.puts "Watching #{Code.new(arg_string)}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_hook
|
95
|
+
hook = [:after_eval, :watch_expression]
|
96
|
+
unless _pry_.hooks.hook_exists?(*hook)
|
97
|
+
_pry_.hooks.add_hook(*hook) do |_, _pry_|
|
98
|
+
eval_and_print_changed _pry_.output
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
Pry::Commands.add_command(Pry::Command::WatchExpression)
|
105
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::WatchExpression
|
3
|
+
class Expression
|
4
|
+
attr_reader :target, :source, :value, :previous_value, :_pry_
|
5
|
+
|
6
|
+
def initialize(_pry_, target, source)
|
7
|
+
@_pry_ = _pry_
|
8
|
+
@target = target
|
9
|
+
@source = source.strip
|
10
|
+
end
|
11
|
+
|
12
|
+
def eval!
|
13
|
+
@previous_value = @value
|
14
|
+
@value = Pry::ColorPrinter.pp(target_eval(target, source), "")
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"#{Code.new(source).strip} => #{value}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Has the value of the expression changed?
|
22
|
+
#
|
23
|
+
# We use the pretty-printed string represenation to detect differences
|
24
|
+
# as this avoids problems with dup (causes too many differences) and == (causes too few)
|
25
|
+
def changed?
|
26
|
+
(value != previous_value)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def target_eval(target, source)
|
32
|
+
target.eval(source)
|
33
|
+
rescue => e
|
34
|
+
e
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Whereami < Pry::ClassCommand
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :method_size_cutoff
|
6
|
+
end
|
7
|
+
|
8
|
+
@method_size_cutoff = 30
|
9
|
+
|
10
|
+
match 'whereami'
|
11
|
+
description 'Show code surrounding the current context.'
|
12
|
+
group 'Context'
|
13
|
+
|
14
|
+
banner <<-'BANNER'
|
15
|
+
Usage: whereami [-qn] [LINES]
|
16
|
+
|
17
|
+
Describe the current location. If you use `binding.pry` inside a method then
|
18
|
+
whereami will print out the source for that method.
|
19
|
+
|
20
|
+
If a number is passed, then LINES lines before and after the current line will be
|
21
|
+
shown instead of the method itself.
|
22
|
+
|
23
|
+
The `-q` flag can be used to suppress error messages in the case that there's
|
24
|
+
no code to show. This is used by pry in the default before_session hook to show
|
25
|
+
you when you arrive at a `binding.pry`.
|
26
|
+
|
27
|
+
The `-n` flag can be used to hide line numbers so that code can be copy/pasted
|
28
|
+
effectively.
|
29
|
+
|
30
|
+
When pry was started on an Object and there is no associated method, whereami
|
31
|
+
will instead output a brief description of the current object.
|
32
|
+
BANNER
|
33
|
+
|
34
|
+
def setup
|
35
|
+
@file = expand_path(target.eval('__FILE__'))
|
36
|
+
@line = target.eval('__LINE__')
|
37
|
+
@method = Pry::Method.from_binding(target)
|
38
|
+
end
|
39
|
+
|
40
|
+
def options(opt)
|
41
|
+
opt.on :q, :quiet, "Don't display anything in case of an error"
|
42
|
+
opt.on :n, :"no-line-numbers", "Do not display line numbers"
|
43
|
+
opt.on :m, :"method", "Show the complete source for the current method."
|
44
|
+
opt.on :c, :"class", "Show the complete source for the current class or module."
|
45
|
+
opt.on :f, :"file", "Show the complete source for the current file."
|
46
|
+
end
|
47
|
+
|
48
|
+
def code
|
49
|
+
@code ||= if opts.present?(:m)
|
50
|
+
method_code or raise CommandError, "Cannot find method code."
|
51
|
+
elsif opts.present?(:c)
|
52
|
+
class_code or raise CommandError, "Cannot find class code."
|
53
|
+
elsif opts.present?(:f)
|
54
|
+
Pry::Code.from_file(@file)
|
55
|
+
elsif args.any?
|
56
|
+
code_window
|
57
|
+
else
|
58
|
+
default_code
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def code?
|
63
|
+
!!code
|
64
|
+
rescue MethodSource::SourceNotFoundError
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def bad_option_combination?
|
69
|
+
[opts.present?(:m), opts.present?(:f),
|
70
|
+
opts.present?(:c), args.any?].count(true) > 1
|
71
|
+
end
|
72
|
+
|
73
|
+
def location
|
74
|
+
"#{@file} @ line #{@line} #{@method && @method.name_with_owner}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def process
|
78
|
+
if bad_option_combination?
|
79
|
+
raise CommandError, "Only one of -m, -c, -f, and LINES may be specified."
|
80
|
+
end
|
81
|
+
|
82
|
+
if nothing_to_do?
|
83
|
+
return
|
84
|
+
elsif internal_binding?(target)
|
85
|
+
handle_internal_binding
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
89
|
+
set_file_and_dir_locals(@file)
|
90
|
+
|
91
|
+
out = "\n#{text.bold('From:')} #{location}:\n\n" <<
|
92
|
+
code.with_line_numbers(use_line_numbers?).with_marker(marker) << "\n"
|
93
|
+
|
94
|
+
_pry_.pager.page out
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def nothing_to_do?
|
100
|
+
opts.quiet? && (internal_binding?(target) || !code?)
|
101
|
+
end
|
102
|
+
|
103
|
+
def use_line_numbers?
|
104
|
+
!opts.present?(:n)
|
105
|
+
end
|
106
|
+
|
107
|
+
def marker
|
108
|
+
!opts.present?(:n) && @line
|
109
|
+
end
|
110
|
+
|
111
|
+
def top_level?
|
112
|
+
target_self == Pry.main
|
113
|
+
end
|
114
|
+
|
115
|
+
def handle_internal_binding
|
116
|
+
if top_level?
|
117
|
+
output.puts "At the top level."
|
118
|
+
else
|
119
|
+
output.puts "Inside #{Pry.view_clip(target_self)}."
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def small_method?
|
124
|
+
@method.source_range.count < self.class.method_size_cutoff
|
125
|
+
end
|
126
|
+
|
127
|
+
def default_code
|
128
|
+
if method_code && small_method?
|
129
|
+
method_code
|
130
|
+
else
|
131
|
+
code_window
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def code_window
|
136
|
+
Pry::Code.from_file(@file).around(@line, window_size)
|
137
|
+
end
|
138
|
+
|
139
|
+
def method_code
|
140
|
+
return @method_code if @method_code
|
141
|
+
|
142
|
+
if valid_method?
|
143
|
+
@method_code = Pry::Code.from_method(@method)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# This either returns the `target_self`
|
148
|
+
# or it returns the class of `target_self` if `target_self` is not a class.
|
149
|
+
# @return [Pry::WrappedModule]
|
150
|
+
def target_class
|
151
|
+
target_self.is_a?(Module) ? Pry::WrappedModule(target_self) :
|
152
|
+
Pry::WrappedModule(target_self.class)
|
153
|
+
end
|
154
|
+
|
155
|
+
def class_code
|
156
|
+
return @class_code if @class_code
|
157
|
+
|
158
|
+
mod = @method ? Pry::WrappedModule(@method.owner) : target_class
|
159
|
+
|
160
|
+
idx = mod.candidates.find_index { |v| expand_path(v.source_file) == @file }
|
161
|
+
@class_code = idx && Pry::Code.from_module(mod, idx)
|
162
|
+
end
|
163
|
+
|
164
|
+
def valid_method?
|
165
|
+
@method && @method.source? && expand_path(@method.source_file) == @file &&
|
166
|
+
@method.source_range.include?(@line)
|
167
|
+
end
|
168
|
+
|
169
|
+
def expand_path(f)
|
170
|
+
return if !f
|
171
|
+
|
172
|
+
if Pry.eval_path == f
|
173
|
+
f
|
174
|
+
else
|
175
|
+
File.expand_path(f)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def window_size
|
180
|
+
if args.empty?
|
181
|
+
_pry_.config.default_window_size
|
182
|
+
else
|
183
|
+
args.first.to_i
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
Pry::Commands.add_command(Pry::Command::Whereami)
|
189
|
+
Pry::Commands.alias_command '@', 'whereami'
|
190
|
+
end
|