Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the decorators to set up interceptable methods and define the interceptor without the configuration. #14

Open
shiroyuki opened this issue Feb 7, 2013 · 0 comments

Comments

@shiroyuki
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant