-
Notifications
You must be signed in to change notification settings - Fork 0
BARN-180: Add find_all_tokens method to parameter substitution to all… #73
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| PATH | ||
| remote: . | ||
| specs: | ||
| parameter_substitution (3.1.0) | ||
| parameter_substitution (3.2.0) | ||
| activesupport (>= 6.0) | ||
| builder (~> 3.2) | ||
| invoca-utils (~> 0.3) | ||
|
|
@@ -22,7 +22,7 @@ | |
| tzinfo (~> 2.0) | ||
| appraisal (2.5.0) | ||
| bundler | ||
| rake | ||
|
Check failure on line 25 in Gemfile.lock
|
||
| thor (>= 0.14.0) | ||
| appraisal-matrix (0.2.0) | ||
| appraisal (~> 2.2) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,18 @@ def find_tokens(string_with_tokens, mapping: {}, context_overrides: {}) | |
| parse_expression(context).substitution_parameter_names | ||
| end | ||
|
|
||
| # Returns all substitution parameter names found in the input string, including | ||
| # those nested inside method call arguments. | ||
| # | ||
| # @param string_with_tokens [String] the input string containing tokens | ||
| # @param mapping [Hash] the mapping of parameters to values | ||
| # @param context_overrides [Hash] optional overrides for context attributes | ||
| # @return [Array<String>] all parameter names, including nested ones | ||
| def find_all_tokens(string_with_tokens, mapping: {}, context_overrides: {}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A method doc might be nice here. |
||
| context = build_context(string_with_tokens, mapping, context_overrides) | ||
| parse_expression(context).all_substitution_parameter_names | ||
| end | ||
|
|
||
| def find_formatters(string_with_tokens, mapping: {}, context_overrides: {}) | ||
| context = build_context(string_with_tokens, mapping, context_overrides) | ||
| parse_expression(context).method_names | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ParameterSubstitution | ||
| VERSION = "3.1.0" | ||
| VERSION = "3.2.0" | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,44 @@ def parse_expression(parameter_expression, context_options = {}) | |
| end | ||
| end | ||
|
|
||
| context "#all_substitution_parameter_names" do | ||
| it "returns top-level parameter names" do | ||
| expression = parse_expression("<simple_text><param_two>") | ||
|
|
||
| expect(expression.all_substitution_parameter_names).to eq(["simple_text", "param_two"]) | ||
| end | ||
|
|
||
| it "returns nested parameter names from method call arguments" do | ||
| expression = parse_expression("<simple_text.if_nil(<another_simple_text>)>") | ||
|
|
||
| expect(expression.all_substitution_parameter_names).to eq(["simple_text", "another_simple_text"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: would you mind adding a space between the expect statements and the test setup?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at all. |
||
| end | ||
|
|
||
| it "returns deeply nested parameter names" do | ||
| expression = parse_expression("<simple_text.if_nil(<another_simple_text.if_nil(<color>)>)>") | ||
|
|
||
| expect(expression.all_substitution_parameter_names).to eq(["simple_text", "another_simple_text", "color"]) | ||
| end | ||
|
|
||
| it "returns nested parameter names with formatters applied" do | ||
| expression = parse_expression("<simple_text.if_nil(<another_simple_text.downcase>)>") | ||
|
|
||
| expect(expression.all_substitution_parameter_names).to eq(["simple_text", "another_simple_text"]) | ||
| end | ||
|
|
||
| it "returns parameter names from multiple top-level expressions with nesting" do | ||
| expression = parse_expression("<simple_text.if_nil(<color>)><another_simple_text.if_nil(<integer>)>") | ||
|
|
||
| expect(expression.all_substitution_parameter_names).to eq(["simple_text", "color", "another_simple_text", "integer"]) | ||
| end | ||
|
|
||
| it "returns empty array for plain text" do | ||
| expression = parse_expression("just plain text") | ||
|
|
||
| expect(expression.all_substitution_parameter_names).to eq([]) | ||
| end | ||
| end | ||
|
|
||
| context "#method_names" do | ||
| it "return expression list method names" do | ||
| expression = parse_expression("<simple_text.do_a_barrel_roll><foo.bar>") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should get rid of the
find_tokensmethod? I see it used in one other place in web other than the mapper (in TokenReplacement). It looks like it's extracting tokens from a webhook url template. It feels like a bug that we're only finding top-level tokens in that case as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is a bug, we should hit the birds up to fix. I don't think we should concern ourselves with that behavior. Also, the url template might not support nested params (just a thought).