Suppose we have two methods where one is interceptable and the another is an interceptor.
from imagination.action import EventType
from imagination.interception import InterceptableMethod, CallableInterceptor
@InterceptableMethod('interceptable_name_a')
def method_a(x):
print(x)
@CallableInterceptor(
EventType.PRE_CONDITION,
'interceptable_name_a',
options=[CallableInterceptor.RAISE_UNDEFINED_TARGET_EXCEPTION]
)
def method_b(x):
print(
'It is greater than 10.'\
if x > 10
else 'It is less than 10.'
)
If method_a is executed, method_b should be executed before method_a while using the same parameters.
It also should work with any registered imagination.entity.Entity where the name of the interceptable point is the composition of the entity ID and the name of the method in the following pattern
entity_id.method_name
By default, CallableInterceptor will do nothing if the reference point of interception doesn't exist.
Suppose we have two methods where one is interceptable and the another is an interceptor.
If
method_a
is executed,method_b
should be executed beforemethod_a
while using the same parameters.It also should work with any registered
imagination.entity.Entity
where the name of the interceptable point is the composition of the entity ID and the name of the method in the following patternBy default,
CallableInterceptor
will do nothing if the reference point of interception doesn't exist.