| Class | Rools::DefaultParameterProc |
| In: |
lib/rools/default_parameter_proc.rb
|
| Parent: | Base |
The DefaultParameterProc binds to a Rule and is allows the block to use method_missing to refer to the asserted object.
Determines whether a method is vital to the functionality of the class.
# File lib/rools/default_parameter_proc.rb, line 11
11: def self.is_vital(method)
12: return method =~ /__(.+)__|method_missing|instance_eval/
13: end
The "rule" parameter must respond to an :assert method. The "b" parameter is a block that will be rebound to this instance.
# File lib/rools/default_parameter_proc.rb, line 24
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
Call the bound block and set the working object so that it can be referred to by method_missing
# File lib/rools/default_parameter_proc.rb, line 33
33: def call(obj)
34: #@working_object = obj
35: status = instance_eval(&@proc)
36: #@working_object = nil
37: return status
38: end
Parameterless method calls by the attached block are assumed to be references to the working object
# File lib/rools/default_parameter_proc.rb, line 47
47: def method_missing(sym, *args)
48: # puts "method missing: #{sym} args:#{args.inspect}"
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: raise Exception, "symbol: #{sym} not found in facts"
57: end
58: #rescue Exception => e
59: # puts "miss exception #{e} #{e.backtrace.join("\n")}"
60: # return nil
61: #end
62: end