public
Fork of wycats/thor
Description: A scripting framework that replaces rake and sake
Homepage: http://www.yehudakatz.com
Clone URL: git://github.com/jackdempsey/thor.git
Search Repo:
add method to get more than top level constants; show failing spec for 
constants_in_contents
jackdempsey (author)
Sat Jul 19 08:00:06 -0700 2008
commit  008938ecb753061ee8543550f4d5254a0d6566fe
tree    e2f60cdefc05bf5443e9261489c4884d6b6dc29e
parent  3acb44b12a406ea3e557ae3600602493b99e2eb4
...
42
43
44
45
46
47
 
 
 
 
 
48
49
50
 
51
52
53
...
42
43
44
 
 
 
45
46
47
48
49
50
51
 
52
53
54
55
0
@@ -42,12 +42,14 @@ class Thor
0
     def self.get_constants_for(klass)
0
       top_level_constants = make_constant(klass).constants
0
       return if top_level_constants.empty?
0
- top_level_constants.dup.each do |const|
0
- if (children = get_constants_for("#{klass}::#{const}"))
0
- top_level_constants << children.map {|child| "#{const}::#{child}"}
0
+ ret = []
0
+ top_level_constants.each do |const|
0
+ klass_name = "#{klass}::#{const}"
0
+ if (children = get_constants_for(klass_name) )
0
+ ret << children.map {|child| "#{const}::#{child}"}
0
         end
0
       end
0
- top_level_constants.flatten
0
+ (top_level_constants + ret).flatten
0
     end
0
 
0
   end
...
89
90
91
92
93
 
94
95
96
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
89
90
91
 
92
93
94
95
96
...
117
118
119
 
 
 
120
121
122
123
124
 
125
126
127
0
@@ -89,8 +89,8 @@ describe Thor::Util do
0
       list = Thor::Util.constants_in_contents("FOO = 12; Bar = {}; class Baz; end; class Baz::Bam; end")
0
       list.must include("FOO")
0
       list.must include("Bar")
0
- list.must include("Baz::Bam")
0
       list.must include("Baz")
0
+ list.must include("Baz::Bam")
0
     end
0
 
0
     it "doesn't put the newly-defined constants in the enclosing namespace" do
0
@@ -117,15 +117,11 @@ describe Thor::Util do
0
             end
0
           end
0
         end
0
- class Box; end
0
- class Box::Cutter; end
0
-
0
         Thor::Util.get_constants_for("Foo").must include("Baz::Bar")
0
         Thor::Util.get_constants_for("Foo").must include("Baz::Bar::Bam")
0
         Thor::Util.get_constants_for("Foo").must include("Baz::Bar::Bat")
0
         Thor::Util.get_constants_for("Foo").must include("Baz::Bar::Bam::Boo")
0
         Thor::Util.get_constants_for("Foo").must include("Baz::Bar::Bam::Bor")
0
- Thor::Util.get_constants_for("Box").must include("Cutter")
0
       end
0
     end
0
 

Comments

    No one has commented yet.