2012-08-11 20:22:29 -04:00
|
|
|
class Pry
|
2012-12-25 16:35:17 -05:00
|
|
|
class Command::JumpTo < Pry::ClassCommand
|
|
|
|
match 'jump-to'
|
2012-08-11 21:26:59 -04:00
|
|
|
group 'Navigating Pry'
|
2013-01-09 15:23:19 -05:00
|
|
|
description 'Jump to a binding further up the stack.'
|
|
|
|
|
|
|
|
banner <<-'BANNER'
|
|
|
|
Jump to a binding further up the stack, popping all bindings below.
|
|
|
|
BANNER
|
2012-08-11 20:22:29 -04:00
|
|
|
|
2012-08-11 21:26:59 -04:00
|
|
|
def process(break_level)
|
2014-09-01 04:24:45 -04:00
|
|
|
break_level = break_level.to_i
|
|
|
|
nesting_level = _pry_.binding_stack.size - 1
|
|
|
|
max_nest_level = nesting_level - 1
|
2012-08-11 20:22:29 -04:00
|
|
|
|
2012-08-11 21:26:59 -04:00
|
|
|
case break_level
|
2015-01-15 01:01:04 -05:00
|
|
|
when nesting_level
|
|
|
|
output.puts "Already at nesting level #{nesting_level}"
|
|
|
|
when 0..max_nest_level
|
|
|
|
_pry_.binding_stack = _pry_.binding_stack[0..break_level]
|
|
|
|
else
|
|
|
|
output.puts "Invalid nest level. Must be between 0 and " \
|
|
|
|
"#{max_nest_level}. Got #{break_level}."
|
2012-08-11 21:26:59 -04:00
|
|
|
end
|
2012-08-11 20:22:29 -04:00
|
|
|
end
|
|
|
|
end
|
2012-12-25 16:35:17 -05:00
|
|
|
|
|
|
|
Pry::Commands.add_command(Pry::Command::JumpTo)
|
2012-08-11 20:22:29 -04:00
|
|
|
end
|