Created
November 6, 2010 16:44
-
-
Save cpetschnig/665528 to your computer and use it in GitHub Desktop.
Patch for oggy/looksee: Added config option 'order'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7878ed28ba6bafbe4f90286f4b86ab35e223939e Mon Sep 17 00:00:00 2001 | |
From: Christoph Petschnig <[email protected]> | |
Date: Fri, 5 Nov 2010 19:10:37 +0100 | |
Subject: [PATCH] Added config option #order | |
--- | |
lib/looksee.rb | 21 ++++++++++++++++++++- | |
spec/looksee_spec.rb | 10 ++++++++++ | |
2 files changed, 30 insertions(+), 1 deletions(-) | |
diff --git a/lib/looksee.rb b/lib/looksee.rb | |
index c0016bb..a6733ca 100644 | |
--- a/lib/looksee.rb | |
+++ b/lib/looksee.rb | |
@@ -56,6 +56,7 @@ require "looksee/version" | |
# | |
# Looksee.default_lookup_path_options | |
# Looksee.default_width | |
+# Looksee.order | |
# Looksee.styles | |
# | |
# See their docs. | |
@@ -103,6 +104,22 @@ module Looksee | |
attr_accessor :default_width | |
# | |
+ # The order in which to print the modules. | |
+ # | |
+ # Possible values are: | |
+ # | |
+ # * :top_down | |
+ # * :bottom_up | |
+ # | |
+ # :top_down will start with the objects class and go down to Kernel | |
+ # (Ruby 1.8) or BasicObject (Ruby 1.9), whereas :bottom_up prints the | |
+ # modules in reverse order. | |
+ # | |
+ # Default: :top_down | |
+ # | |
+ attr_accessor :order | |
+ | |
+ # | |
# The default styles to use for the +inspect+ strings. | |
# | |
# This is a hash with keys: | |
@@ -137,8 +154,9 @@ module Looksee | |
def lookup_modules(object) | |
modules = [] | |
klass = Looksee.internal_class(object) | |
+ insert_method = @order != :bottom_up ? :push : :unshift | |
while klass | |
- modules << Looksee.internal_class_to_module(klass) | |
+ modules.send(insert_method, Looksee.internal_class_to_module(klass)) | |
klass = Looksee.internal_superclass(klass) | |
end | |
modules | |
@@ -147,6 +165,7 @@ module Looksee | |
self.default_lookup_path_options = {:public => true, :protected => true, :undefined => true, :overridden => true} | |
self.default_width = 80 | |
+ self.order = :top_down | |
self.styles = { | |
:module => "\e[1;37m%s\e[0m", # white | |
:public => "\e[1;32m%s\e[0m", # green | |
diff --git a/spec/looksee_spec.rb b/spec/looksee_spec.rb | |
index bad5f57..67bcada 100644 | |
--- a/spec/looksee_spec.rb | |
+++ b/spec/looksee_spec.rb | |
@@ -368,6 +368,16 @@ describe Looksee::LookupPath do | |
end | |
end | |
+ describe "order" do | |
+ it "should return the modules in the specified order" do | |
+ default_order_mods = Looksee.lookup_modules("a string") | |
+ Looksee.order = :bottom_up | |
+ default_order_mods.reverse.should == Looksee.lookup_modules("a string") | |
+ Looksee.order = :top_down | |
+ default_order_mods.should == Looksee.lookup_modules("a string") | |
+ end | |
+ end | |
+ | |
describe "styles" do | |
before do | |
styles = { | |
-- | |
1.7.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment