Class: Looksee::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/looksee/inspector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @lookup_path = lookup_path
  @visibilities = (vs = options[:visibilities]) ? vs.to_set : Set[]
  @filters = (fs = options[:filters]) ? fs.to_set : Set[]
  @width = options[:width] || ENV['COLUMNS'].to_i.nonzero? || Looksee.default_width
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



12
13
14
# File 'lib/looksee/inspector.rb', line 12

def filters
  @filters
end

#lookup_pathObject (readonly)

Returns the value of attribute lookup_path.



10
11
12
# File 'lib/looksee/inspector.rb', line 10

def lookup_path
  @lookup_path
end

#visibilitiesObject (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

#inspectObject

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