Is there a way to remove a rule from the rulebase at runtime?
I want to create a rules engine that is exposed as a webservice.
Clients will post to /facts/assert to put a new fact into the working
memory and will post to /facts/retract to remove a fact from the
working memory. I currently start my environment by creating a single
engine and single rulebook:
//happens on start:
RULER_ENGINE = Ruleby::Core::Engine.new
RULE_BOOK = SimpleRulebook.new(RULER_ENGINE)
RULE_BOOK.rules //loads rules from external source
In my facts controller I have something like this:
def assert
RULER_ENGINE.assert CoolObj.new(params[:obj])
RULER_ENGINE.match
render :nothing => true
end
def retract
GarbageManRules.new(RULER_ENGINE) do |rb|
rb.rule [CoolObj, :c,
m.pk == params[:pk], m.type == params
[:type]] do |v|
rb.retract(v[:c])
end
end
RULER_ENGINE.match
render :nothing => true
end
My understanding is that when I add the rule to the rulebase..its
there forever. In my case its really a transient rule just used to
remove something from the working memory and should be removed after
that action. Am I maybe approaching this wrong? Is there a way to
remove this rule from the rulebase once I am done with it?