Skip to content

Commit

Permalink
Update documentation and examples for new transforms structure
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmreed committed Apr 20, 2020
1 parent 6a028ed commit 616474c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/test_data_transforms/example_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MultiplyTransformer(TransformProvider):
transform_name = "multiply"
allowed_types = ["xsd:string"]

def _get_transform(self, field_context: str, options: Dict):
def _get_transform(self, field_context: Dict, options: Dict):
def multiply(x):
return x * options["count"]

Expand Down
6 changes: 4 additions & 2 deletions docs/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ Amaxa ships with five transforms:
Custom Transforms
*****************

Amaxa also supports custom transforms. To implement a custom transformation, create a Python module containing a class that subclasses ``amaxa.transforms.TransformProvider``. Subclasses must populate the ``transform_name`` class attribute and override two methods, ``get_transform()`` and ``get_options_schema()``.
Amaxa also supports custom transforms. To implement a custom transformation, create a Python module containing a class that subclasses ``amaxa.transforms.TransformProvider``. Subclasses must populate the ``transform_name`` class attribute and override two methods, ``_get_transform()`` and ``get_options_schema()``.

``get_transform()`` accepts the API name of the configured field and a ``dict`` containing the user-specified options, if any. It returns a callable that will be invoked with a single parameter, the field value, each time the transform is used.
``_get_transform()`` accepts a ``dict`` representing the describe of the configured field and a ``dict`` containing the user-specified options, if any. It returns a callable that will be invoked with a single parameter, the field value, each time the transform is used.

``get_options_schema()`` returns the schema by which the user-specifiable options will be validated in the operation definition. This is a `Cerberus <https://docs.python-cerberus.org/>`_ schema that should validate a ``dict``.

Transforms may optionally override ``_validate_field()``, which also accepts a ``dict`` representing the describe of the configured field. This method should raise a ``TransformException`` if the transform cannot be applied to this field for any reason. The default implementation requires that the field's ``soapType`` attribute be one of the values in the class attribute ``allowed_types``, a string list.

Before being used in an operation, custom transforms must be loaded by specifying them in a ``plugin-modules`` list at the top level of the YAML configuration. Specify the name of the containing module, not the transform class; Amaxa will automatically discover transforms in those modules. Modules may be located in the current working directory or anywhere in the Python search path.

A complete example of using a custom transform is included in Amaxa's repository in the ``assets/test_data_transforms`` directory.

0 comments on commit 616474c

Please sign in to comment.