Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/Context/Bridge.rb | 64 | 41 | 84.38%
|
78.05%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 module Context |
2 |
3 # This class is used to specify the namespace for a symbol |
4 # according to a priority list. When you create the Bridge |
5 # you initialize it either with a single module name, or an |
6 # array of module names. Calling "bridge.symbol" will return |
7 # the class in desired namespace (or nil if it doesn't exist) |
8 # If the Bridge was initialized with an array, it will pick |
9 # the first namespace that evaluates the symbol into something |
10 # that actually exists. |
11 class Bridge |
12 |
13 # Takes either a module name, or an array of module names |
14 def initialize(mods) |
15 if mods.class != Array |
16 @mod = mods |
17 @mods = nil |
18 else |
19 @mods = mods |
20 @mod = nil |
21 end |
22 end |
23 |
24 # Convert the module name and symbol to a string |
25 def symbolToS(mod, symbol) |
26 mod.to_s + "::" + symbol.to_s |
27 end |
28 |
29 # Evaluate the module and symbol, returning the class. |
30 # If it doesn't exist, return nil |
31 def evalClass(mod, symbol) |
32 retVal = nil |
33 if !mod.nil? |
34 begin |
35 retVal = mod.class_eval(symbol.to_s) |
36 rescue |
37 end |
38 end |
39 return retVal |
40 end |
41 |
42 # Returns true if the mod and symbol evaluate to a class in the system. |
43 def classExists?(mod, symbol) |
44 symbolToS(mod, symbol).eql?(evalClass(mod, symbol).to_s) |
45 end |
46 |
47 # Return the class specified by the stored module and the symbol |
48 # If an array of modules was stored, walk through them and pick |
49 # the first one that creates an extant class. |
50 def method_missing(symbol) |
51 if !@mod.nil? |
52 @mod.class_eval(symbol.to_s) |
53 elsif !@mods.nil? |
54 mod = @mods.find do |mod| |
55 classExists?(mod, symbol) |
56 end |
57 evalClass(mod, symbol) |
58 else |
59 nil |
60 end |
61 end |
62 |
63 end |
64 end |
Generated on Mon May 23 16:17:45 +0900 2011 with rcov 0.9.8