Skip to content

Commit

Permalink
[transform] refactor how the custom predefined function works (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
cblades-tc authored Nov 19, 2024
1 parent 1d84b4c commit 8310b9b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- APP-4620 - [transform] Added structured/contextualized exceptions to transform
- APP-4632 - [transform] Added support for attribute.pinned field
- APP-4640 - [api] Updated API hashing method to use SHA256 for FIPS compliance

- APP-4656 - [transform] refactor how the custom predefined function works

## 4.0.6

Expand Down
50 changes: 31 additions & 19 deletions tcex/api/tc/ti_transform/ti_predefined_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,39 @@ class ProcessingFunctions:
def __init__(self, tcex) -> None:
"""."""
self.tcex = tcex
self.custom_fns = {}

def custom(self, value, description: str):
@custom_function_definition(
{
'name': 'custom',
'label': 'Custom',
'help': 'Describe a custom processing function.',
'params': [
{
'default': None,
'name': 'name',
'label': 'Name',
'type': 'str',
'help': 'A unique name for this custom processing function.',
'required': True,
},
{
'default': None,
'name': 'description',
'label': 'Description',
'type': 'str',
'help': 'Describe the custom processing function.',
'required': True,
},
],
}
)
def custom(self, value, name: str, description: str, ti_dict, transform, **kwargs):
"""Allow for custom processing to be described."""
raise RuntimeError(f'Custom function not implemented: {description}')
fn = self.custom_fns.get(name.lower())
if not fn:
raise NotImplementedError(f'Custom function not implemented: {description}')
return fn(value, ti_dict=ti_dict, transform=transform, **kwargs)

def static_map(self, value, mapping: dict):
"""Map values to static values.
Expand All @@ -122,23 +151,6 @@ def value_in(self, value, values: str, delimiter: str = ','):

return value if value in [v.strip() for v in json.loads(values).split(delimiter)] else None

@custom_function_definition(
{
'name': 'format_table',
'label': 'Format Objects as Markdown Table',
'help': 'Format a list of objects as a markdown table.',
'params': [
{
'default': None,
'name': 'column_order',
'label': 'Column Order',
'type': 'str',
'help': 'The order of the columns.',
'required': False,
}
],
}
)
def format_table(self, value, column_order: str):
"""Format a markdown table.
Expand Down

0 comments on commit 8310b9b

Please sign in to comment.