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

Variable function evaluator #572

Merged
merged 3 commits into from
Apr 7, 2021

Conversation

GregDThomas
Copy link
Contributor

This PR adds the ability to supply a "Variable Function" - a java.util.Function<String, Object> that will map a variable name to it's value.

This is useful when you do not know the variables that may exist in a template at run time. Rather than populate the Map<String, Object> with every possible variable that can be supported, simply set the variable function that will be called at runtime. The code in your Function can then determine the value when it is needed.

Note that this is slightly different to the LazyExpression concept that already exists - this is a Supplier, so requires the caller to know the list of variables to populate in advance.

@GregDThomas
Copy link
Contributor Author

Note; this is my first PR for this project; firstly thank for maintaining it, secondly if you want any improvements to be made in order to get this merged, please let me know and I'll see what I can do.

@GregDThomas
Copy link
Contributor Author

PPS. Should also say I added a Maven wrapper as well; simply invoke mvnw instead of mvn if you don't alreaedy have the correct version of Maven installed.

@GregDThomas GregDThomas force-pushed the variable-function-evaluator branch 2 times, most recently from d7b83aa to 817c409 Compare December 22, 2020 10:39
@GregDThomas GregDThomas force-pushed the variable-function-evaluator branch from 817c409 to 730a769 Compare January 22, 2021 11:25
@GregDThomas
Copy link
Contributor Author

Hi - any thoughts of what would need to be changed to get this merged? Thanks :)

@matthewwells
Copy link

+1 - This would be a really useful enhancement. I have an exact use case for this dynamic processing of the variable names.

@bhreinb
Copy link
Contributor

bhreinb commented Mar 15, 2021

+1 - for this PR...I have a use case with this PR in that I'd like to override the default value for a variable when It's not found...so hopefully it can be merged soon 🙏

@lordnelson
Copy link

This is a useful feature to resolve many template variables supplied from multiple sources

@akseiya
Copy link

akseiya commented Mar 29, 2021

+1 for this PR, for complex templates and costly variables (say we need to call APIs to have values) it's super useful to know at template resolution time which ones are needed and which ones are not

Copy link
Contributor

@jasmith-hs jasmith-hs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, it is a very nice option

@jasmith-hs jasmith-hs merged commit f0cc594 into HubSpot:master Apr 7, 2021
@GregDThomas GregDThomas deleted the variable-function-evaluator branch April 7, 2021 19:05
@GregDThomas
Copy link
Contributor Author

Thank you for merging it, and your continued work on the project!

@jasmith-hs jasmith-hs mentioned this pull request May 28, 2022
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.

6 participants