Class: Rools::DefaultParameterProc
- Inherits:
-
Base
- Object
- Base
- Rools::DefaultParameterProc
- Defined in:
- lib/rools/default_parameter_proc.rb
Overview
The DefaultParameterProc binds to a Rule and is allows the block to use method_missing to refer to the asserted object.
Class Method Summary (collapse)
-
+ (Object) is_vital(method)
Determines whether a method is vital to the functionality of the class.
Instance Method Summary (collapse)
-
- (Object) assert(obj)
Assert a new object up the composition-chain into the current RuleSet.
-
- (Object) call(obj)
Call the bound block and set the working object so that it can be referred to by method_missing.
-
- (Object) fail(message = nil)
Stops the current assertion and change status to :fail.
-
- (DefaultParameterProc) initialize(rule, b)
constructor
The "rule" parameter must respond to an :assert method.
-
- (Object) method_missing(sym, *args)
Parameterless method calls by the attached block are assumed to be references to the working object.
-
- (Object) stop(message = nil)
Stops the current assertion.
Methods inherited from Base
Constructor Details
- (DefaultParameterProc) initialize(rule, b)
The "rule" parameter must respond to an :assert method. The "b" parameter is a block that will be rebound to this instance.
24 25 26 27 28 29 |
# File 'lib/rools/default_parameter_proc.rb', line 24 def initialize(rule, b) raise ArgumentError.new('The "rule" parameter must respond to an :assert method') unless rule.respond_to?(:assert) @rule = rule @proc = b #@working_object = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(sym, *args)
Parameterless method calls by the attached block are assumed to be references to the working object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rools/default_parameter_proc.rb', line 47 def method_missing(sym, *args) # puts "method missing: #{sym} args:#{args.inspect}" # check if it is a fact first #begin facts = @rule.rule_set.get_facts if facts.has_key?( sym.to_s ) #puts "return fact #{facts[sym.to_s].value}" return facts[sym.to_s].value else raise Exception, "symbol: #{sym} not found in facts" end #rescue Exception => e # puts "miss exception #{e} #{e.backtrace.join("\n")}" # return nil #end end |
Class Method Details
+ (Object) is_vital(method)
Determines whether a method is vital to the functionality of the class.
11 12 13 |
# File 'lib/rools/default_parameter_proc.rb', line 11 def self.is_vital(method) return method =~ /__(.+)__|method_missing|instance_eval|object_id/ end |
Instance Method Details
- (Object) assert(obj)
Assert a new object up the composition-chain into the current RuleSet
41 42 43 |
# File 'lib/rools/default_parameter_proc.rb', line 41 def assert(obj) @rule.assert(obj) end |
- (Object) call(obj)
Call the bound block and set the working object so that it can be referred to by method_missing
33 34 35 36 37 38 |
# File 'lib/rools/default_parameter_proc.rb', line 33 def call(obj) #@working_object = obj status = instance_eval(&@proc) #@working_object = nil return status end |
- (Object) fail(message = nil)
Stops the current assertion and change status to :fail
70 71 72 |
# File 'lib/rools/default_parameter_proc.rb', line 70 def fail( = nil) @rule.fail() end |
- (Object) stop(message = nil)
Stops the current assertion. Does not indicate failure.
65 66 67 |
# File 'lib/rools/default_parameter_proc.rb', line 65 def stop( = nil) @rule.stop() end |