1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/list_inspectors.rb
Robert Gleeson b9cddb5609 add 'list-inspectors' & 'change-inspectors' commands.
the list-inspectors command shows a list of available inspectors as well
as the active inspectors in the list. inspectors are drawn with a name as
well as a short description.

change-inspector can be used to change the inspector by the name found in
the list-inspectors command.

an inspector in pry is something that prints a return value in a repl session.
i'm not crazy about the name `inspector` but the traditional name used in pry(`print`)
didn't fit well. some discussion led us to `inspector` for lack of a better word,
see #1176 on github for discussion
2014-03-23 09:21:17 +01:00

34 lines
861 B
Ruby

class Pry::Command::ListInspectors < Pry::ClassCommand
match 'list-inspectors'
group 'inspect'
description 'list the inspector Procs available to use in pry'
banner <<-BANNER
Usage: list-inspectors
list the inspector Proc's available to print ruby objects(e.g: return values) in
a repl session.
BANNER
def process
output.puts heading("Available inspectors") + "\n"
inspector_map.each do |name, inspector|
output.write "name: #{text.bold(name)}"
output.puts selected_inspector?(inspector) ? selected_text : ""
output.puts inspector[:description]
output.puts
end
end
private
def inspector_map
Pry::Inspector::MAP
end
def selected_text
text.red " (selected) "
end
def selected_inspector?(inspector)
_pry_.print == inspector[:value]
end
Pry::Commands.add_command(self)
end