Selectors - Components for Dispatching to Resources

The Selectors module provides classes (although currently only one class is supplied) which act as standard WebStack resources, but which attempt to "select" other resources, dispatch each request to those resources, and to cause various side-effects, mostly on the attributes stored on the transaction object. These "selector" classes behave those in the ResourceMap module, but aspire to be more generally applicable.

Introducing PathSelector

In non-trivial applications, it is often desirable to know the path or URL to a particular resource, especially the "root" resource under which the application or one of its components may reside. The PathSelector class can be instantiated and be made to refer to a resource, recording such path or URL details in an attribute for later inspection.

WebStack API - The PathSelector Class

The PathSelector class (found in the WebStack.Resources.Selectors module) wraps resource objects whose location (as indicated by a path or URL) should be recorded as an attribute on the current transaction. The most common use of the class is to record the "root" resource's location, and this would be done as follows:

def get_site_map():
return PathSelector(MyResource())

Here, the get_site_map function (as described in the "Deploying a WebStack Application" document) would provide a PathSelector object instead of an instance of the MyResource class. However, the side-effect of combining these two resources would be the availability of an attribute named root on the transaction object. Thus, the "root" MyResource object and, indeed, all resource objects visited after this side-effect has occurred will have access to the "root" path or URL information.

Further Reading

The API documentation for the PathSelector class provides additional information.