Skip to content

Add support for custom functions#102

Merged
jamesls merged 4 commits intojmespath:developfrom
jamesls:runtime
Feb 24, 2016
Merged

Add support for custom functions#102
jamesls merged 4 commits intojmespath:developfrom
jamesls:runtime

Conversation

@jamesls
Copy link
Member

@jamesls jamesls commented Feb 23, 2016

This adds support for custom functions. It has these changes:

  • Add custom_functions to the Options class. This is how you can provide custom functions to use.
  • Remove instance variable of interpreter in the Functions class. This was originally added to invoke exprefs, but the cyclic dependency between interpreter and functions made initialization awkward. Each expref now has a reference to the interpreter. This may need some rethinking if other backends besides a tree interpreter are added.
  • Remove the need for a class decorator to populate the function table in the Functions class. Instead this has all been moved out into a metaclass. The benefit here is that you can subclass from this base class and the FUNCTION_TABLE will be automatically populated for you. This makes the extension API more straightforward.

I've added an example in the README (and a testcase) that shows how you can add custom functions.

Closes #100

This moves the cyclic dependency
between functions and interpreters to
expref nodes and functions.

This makes it easier to create custom
function runtime classes as they now have
no instance state.
@jamesls jamesls mentioned this pull request Feb 23, 2016
@jamesls jamesls merged commit 6ccaed4 into jmespath:develop Feb 24, 2016
@meric
Copy link

meric commented Feb 24, 2016

Wow thanks! This will be really useful!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants