C0 code coverage information
Generated on Mon May 21 22:36:02 -0400 2007 with rcov 0.8.0
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 require 'rools/base'
2 module Rools
3
4 # The DefaultParameterProc binds to a Rule and
5 # is allows the block to use method_missing to
6 # refer to the asserted object.
7 class DefaultParameterProc < Base
8
9 # Determines whether a method is vital to the functionality
10 # of the class.
11 def self.is_vital(method)
12 return method =~ /__(.+)__|method_missing|instance_eval/
13 end
14
15 # Removes unnecessary methods from the class to minimize
16 # name collisions with method_missing.
17 for method in instance_methods
18 undef_method(method) unless is_vital(method)
19 end
20
21 # The "rule" parameter must respond to an :assert method.
22 # The "b" parameter is a block that will be rebound to this
23 # instance.
24 def initialize(rule, b)
25 raise ArgumentError.new('The "rule" parameter must respond to an :assert method') unless rule.respond_to?(:assert)
26 @rule = rule
27 @proc = b
28 @working_object = nil
29 end
30
31 # Call the bound block and set the working object so that it
32 # can be referred to by method_missing
33 def call(obj)
34 @working_object = obj
35 status = instance_eval(&@proc)
36 @working_object = nil
37 return status
38 end
39
40 # Assert a new object up the composition-chain into the current RuleSet
41 def assert(obj)
42 @rule.assert(obj)
43 end
44
45 # Parameterless method calls by the attached block are assumed to
46 # be references to the working object
47 def method_missing(sym, *args)
48 #puts "method missing: #{sym}"
49 # check if it is a fact first
50 begin
51 facts = @rule.rule_set.get_facts
52 if facts.has_key?( sym.to_s )
53 #puts "return fact #{facts[sym.to_s].value}"
54 return facts[sym.to_s].value
55 else
56 #puts "#{sym} not in facts"
57 end
58 rescue Exception => e
59 #logger.error "miss exception #{e} #{e.backtrace.join("\n")}" if logger
60 #puts "miss exception #{e} #{e.backtrace.join("\n")}"
61 end
62 return @working_object if @working_object && args.size == 0
63 return nil
64 end
65
66 # Stops the current assertion. Does not indicate failure.
67 def stop(message = nil)
68 @rule.stop(message)
69 end
70
71 # Stops the current assertion and change status to :fail
72 def fail(message = nil)
73 @rule.fail(message)
74 end
75 end
76 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.