Class: Looksee::Inspector
- Inherits:
-
Object
- Object
- Looksee::Inspector
- Defined in:
- lib/looksee/inspector.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#lookup_path ⇒ Object
readonly
Returns the value of attribute lookup_path.
-
#visibilities ⇒ Object
readonly
Returns the value of attribute visibilities.
Instance Method Summary collapse
-
#edit(name) ⇒ Object
Open an editor at the named method’s definition.
-
#initialize(lookup_path, options = {}) ⇒ Inspector
constructor
A new instance of Inspector.
-
#inspect ⇒ Object
Print the method lookup path of self.
- #pretty_print(pp) ⇒ Object
Constructor Details
#initialize(lookup_path, options = {}) ⇒ Inspector
Returns a new instance of Inspector.
3 4 5 6 7 8 |
# File 'lib/looksee/inspector.rb', line 3 def initialize(lookup_path, ={}) @lookup_path = lookup_path @visibilities = (vs = [:visibilities]) ? vs.to_set : Set[] @filters = (fs = [:filters]) ? fs.to_set : Set[] @width = [:width] || ENV['COLUMNS'].to_i.nonzero? || Looksee.default_width end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
12 13 14 |
# File 'lib/looksee/inspector.rb', line 12 def filters @filters end |
#lookup_path ⇒ Object (readonly)
Returns the value of attribute lookup_path.
10 11 12 |
# File 'lib/looksee/inspector.rb', line 10 def lookup_path @lookup_path end |
#visibilities ⇒ Object (readonly)
Returns the value of attribute visibilities.
11 12 13 |
# File 'lib/looksee/inspector.rb', line 11 def visibilities @visibilities end |
Instance Method Details
#edit(name) ⇒ Object
Open an editor at the named method’s definition.
Uses Looksee.editor to determine the editor command to run.
Only works for methods for which file and line numbers are accessible.
42 43 44 |
# File 'lib/looksee/inspector.rb', line 42 def edit(name) Editor.new(Looksee.editor).edit(lookup_path.object, name) end |
#inspect ⇒ Object
Print the method lookup path of self. See the README for details.
17 18 19 20 21 |
# File 'lib/looksee/inspector.rb', line 17 def inspect lookup_path.entries.reverse.map do |entry| inspect_entry(entry) end.join("\n") end |
#pretty_print(pp) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/looksee/inspector.rb', line 23 def pretty_print(pp) # In the default IRB inspect mode (pp), IRB assumes that an inspect string # that doesn't look like a bunch of known patterns is a code blob, and # formats accordingly. That messes up our color escapes. if Object.const_defined?(:IRB) && IRB.const_defined?(:ColorPrinter) && pp.is_a?(IRB::ColorPrinter) PP.instance_method(:text).bind(pp).call(inspect) else pp.text(inspect) end end |