lib/looksee/shortcuts.rb in oggy-looksee-0.1.0 vs lib/looksee/shortcuts.rb in oggy-looksee-0.2.0
- old
+ new
@@ -50,5 +50,58 @@
def dump_lookup_path(*args)
p lookup_path(*args)
self
end
end
+
+module Looksee
+ #
+ # Show a quick reference.
+ #
+ def self.help
+ Help.new
+ end
+
+ class Help
+ def inspect
+ <<-EOS.gsub(/^ *\|/, '')
+ |== Looksee Quick Reference
+ |
+ | lp(object)
+ | object.lookup_path
+ | Print the method lookup path of \`object\'
+ |
+ | lpi(klass)
+ | Print the method lookup path of an instance of \`klass\'.
+ |
+ |Add .grep(/pattern/) to restrict the methods listed:
+ |
+ | lp(object).grep(/foo/)
+ |
+ |== Visibilities
+ |
+ |Methods are printed according to their visibility:
+ |
+ |#{style_info}
+ |
+ |Pass options to specify which visibilities to show:
+ |
+ | lp(object, :private => true, :overridden => false)
+ | lp(object, :private , :overridden => false) # shortcut
+ EOS
+ end
+
+ def style_info
+ max_width = 0
+ styles = [:public, :protected, :private, :undefined, :overridden]
+ data = styles.map do |name|
+ display_style = Looksee.styles[name] % name
+ display_length = display_style.length
+ max_width = display_length if display_length > max_width
+ on = Looksee.default_lookup_path_options[name] ? 'on' : 'off'
+ [display_style, on]
+ end.map do |display_style, on|
+ " * #{display_style.ljust(max_width)} (#{on} by default)"
+ end.join("\n")
+ end
+ end
+end