It would be better to use TemporaryChange instead of implementing a special class for matchingUARules' scope.
Created attachment 193093 [details] Patch
This code has been significantly refactored since this patch was proposed.