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.

Methods

assert   call   fail   is_vital   method_missing   new   stop  

Public Class methods

Determines whether a method is vital to the functionality of the class.

[Source]

    # 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.

[Source]

    # 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

Public Instance methods

Assert a new object up the composition-chain into the current RuleSet

[Source]

    # File lib/rools/default_parameter_proc.rb, line 41
41:     def assert(obj)
42:       @rule.assert(obj)
43:     end

Call the bound block and set the working object so that it can be referred to by method_missing

[Source]

    # 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

Stops the current assertion and change status to :fail

[Source]

    # File lib/rools/default_parameter_proc.rb, line 70
70:     def fail(message = nil)
71:       @rule.fail(message)
72:     end

Parameterless method calls by the attached block are assumed to be references to the working object

[Source]

    # 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

Stops the current assertion. Does not indicate failure.

[Source]

    # File lib/rools/default_parameter_proc.rb, line 65
65:     def stop(message = nil)
66:       @rule.stop(message)
67:     end

[Validate]