parameter_substitution 3.2.0.pre.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e5b52440c6a67aacb8b70595ac82a464ad3dc9ffa882d40a2b0bdaa6bfc8445
4
- data.tar.gz: 9d05190f2f32b431d9072b40f7a639496512bccf7b23fb2b18cf82b4d0fce5b8
3
+ metadata.gz: b1ce2eb4a673fa4ca42d4bfef42b2b18a0b6011dcef6aeb6b8f4c0c0fb30f63b
4
+ data.tar.gz: 41b30435287d1dcb7b0b01686c238a49fad6f1d8bf6b414a96a65099dec17f4b
5
5
  SHA512:
6
- metadata.gz: ececf080e480205c5bea41f0c059b85a8281738f013c750ee8695f82e0a74fb3a2751a85c0b202906b73042f12437cab0bdda13e94b387167e540e42b19d7a11
7
- data.tar.gz: 8273813fb82258784fee6c92ae08422bfafc7a18352deabc14da27d9682d6b8d808795ee6a8560741ca46e1da3c1b7bc5715c4a5cdbc808f5f22d923cef7dc61
6
+ metadata.gz: 3bdabcf306d69fc596a6202bf718f0bcdf3fd53ef4fa3d1a00135e4fb3745846f80c3a21ccfc2e1e73d0488aab7e2ac45e8ae7b578cde55ddf0f9b98fddfe8d6
7
+ data.tar.gz: e86ae64208c6cdf3bdae88bb951d54b379d9a622af44c7a1a7cfc981886b21c80eaf2ad1315549c14785057804ec95580a69cd2d177369e3a44fd7fd21469e0e
@@ -42,6 +42,18 @@ class ParameterSubstitution
42
42
  @expression_list.map_compact(&:parameter_name)
43
43
  end
44
44
 
45
+ # Recursively collects all substitution parameter names, including those
46
+ # nested inside method call arguments.
47
+ #
48
+ # @example
49
+ # # For "<dclid.compare_string(<gclid>, 'a', 'b')>"
50
+ # # returns ["dclid", "gclid"]
51
+ #
52
+ # @return [Array<String>] all parameter names, including nested ones
53
+ def all_substitution_parameter_names
54
+ @expression_list.flat_map { |expr| parameter_names_from_expression(expr) }
55
+ end
56
+
45
57
  def method_names
46
58
  @expression_list.reduce([]) do |all_method_names, expression|
47
59
  all_method_names + methods_used_by_expression(expression)
@@ -142,5 +154,34 @@ class ParameterSubstitution
142
154
  def pluralize_text(text, amount)
143
155
  text + (amount > 1 ? 's' : '')
144
156
  end
157
+
158
+ # Extracts the parameter name from an expression and recursively collects
159
+ # any nested parameter names from its method call arguments.
160
+ #
161
+ # @param expr [TextExpression, SubstitutionExpression] a single expression node
162
+ # @return [Array<String>] parameter names found in this expression and its arguments
163
+ def parameter_names_from_expression(expr)
164
+ if (name = expr.parameter_name)
165
+ [name] + parameter_names_from_method_calls(expr.try(:method_calls))
166
+ else
167
+ []
168
+ end
169
+ end
170
+
171
+ # Collects parameter names from nested Expression arguments within method calls.
172
+ #
173
+ # @param method_calls [Array<MethodCallExpression>, nil] the method calls to inspect
174
+ # @return [Array<String>] parameter names found in nested expression arguments
175
+ def parameter_names_from_method_calls(method_calls)
176
+ if method_calls
177
+ method_calls.flat_map do |method_call|
178
+ method_call.arguments.flat_map do |arg|
179
+ arg.is_a?(Expression) ? arg.all_substitution_parameter_names : []
180
+ end
181
+ end
182
+ else
183
+ []
184
+ end
185
+ end
145
186
  end
146
187
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParameterSubstitution
4
- VERSION = "3.2.0.pre.1"
4
+ VERSION = "3.2.0"
5
5
  end
@@ -69,6 +69,18 @@ class ParameterSubstitution
69
69
  parse_expression(context).substitution_parameter_names
70
70
  end
71
71
 
72
+ # Returns all substitution parameter names found in the input string, including
73
+ # those nested inside method call arguments.
74
+ #
75
+ # @param string_with_tokens [String] the input string containing tokens
76
+ # @param mapping [Hash] the mapping of parameters to values
77
+ # @param context_overrides [Hash] optional overrides for context attributes
78
+ # @return [Array<String>] all parameter names, including nested ones
79
+ def find_all_tokens(string_with_tokens, mapping: {}, context_overrides: {})
80
+ context = build_context(string_with_tokens, mapping, context_overrides)
81
+ parse_expression(context).all_substitution_parameter_names
82
+ end
83
+
72
84
  def find_formatters(string_with_tokens, mapping: {}, context_overrides: {})
73
85
  context = build_context(string_with_tokens, mapping, context_overrides)
74
86
  parse_expression(context).method_names
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parameter_substitution
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0.pre.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-17 00:00:00.000000000 Z
11
+ date: 2026-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -99,7 +99,6 @@ files:
99
99
  - lib/parameter_substitution/formatters/date_us_dashes.rb
100
100
  - lib/parameter_substitution/formatters/date_us_normal.rb
101
101
  - lib/parameter_substitution/formatters/date_year_first_dashes.rb
102
- - lib/parameter_substitution/formatters/dollars_to_cents.rb
103
102
  - lib/parameter_substitution/formatters/downcase.rb
104
103
  - lib/parameter_substitution/formatters/duration_as_seconds.rb
105
104
  - lib/parameter_substitution/formatters/duration_as_time.rb
@@ -149,9 +148,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
148
  version: '3.1'
150
149
  required_rubygems_version: !ruby/object:Gem::Requirement
151
150
  requirements:
152
- - - ">"
151
+ - - ">="
153
152
  - !ruby/object:Gem::Version
154
- version: 1.3.1
153
+ version: '0'
155
154
  requirements: []
156
155
  rubygems_version: 3.3.27
157
156
  signing_key:
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ParameterSubstitution::Formatters::DollarsToCents < ParameterSubstitution::Formatters::Base
4
- def self.description
5
- "Converts a dollar amount to cents as an integer"
6
- end
7
-
8
- def self.format(value)
9
- (Float(value) * 100).round.to_i rescue nil
10
- end
11
- end