parameter_substitution 3.2.0.pre.1 → 3.2.0.pre.2

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: a8217b83c3c18c7859547a4085b54d5e044eb112e5d3ecb0406e1d8c25eca05b
4
+ data.tar.gz: 95fecf90965e89d74232b9f9c9827f250cf540a29b5f9ca52a137c834c341e11
5
5
  SHA512:
6
- metadata.gz: ececf080e480205c5bea41f0c059b85a8281738f013c750ee8695f82e0a74fb3a2751a85c0b202906b73042f12437cab0bdda13e94b387167e540e42b19d7a11
7
- data.tar.gz: 8273813fb82258784fee6c92ae08422bfafc7a18352deabc14da27d9682d6b8d808795ee6a8560741ca46e1da3c1b7bc5715c4a5cdbc808f5f22d923cef7dc61
6
+ metadata.gz: 952f7ff4d93e043221e3fd49f0143e8c770c3fb5242472852b46ddbf922b9d5ebaa4a3b483aeab769a5ce179ca735ed30970be017ce50c8655c17594adb76726
7
+ data.tar.gz: 5a7b43f9fd00781ca6f1eb4afc56340cc32fb05a16f4bf0a1aa707efc81ce0235ce23b75239199ffb7178348698fcfdcf4f81f797a44fb3d05a7ebd98b8bf9be
@@ -42,6 +42,13 @@ 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 (e.g. <dclid.compare_string(<gclid>, 'a', 'b')>
47
+ # returns both "dclid" and "gclid").
48
+ def all_substitution_parameter_names
49
+ @expression_list.flat_map { |expr| parameter_names_from_expression(expr) }
50
+ end
51
+
45
52
  def method_names
46
53
  @expression_list.reduce([]) do |all_method_names, expression|
47
54
  all_method_names + methods_used_by_expression(expression)
@@ -142,5 +149,23 @@ class ParameterSubstitution
142
149
  def pluralize_text(text, amount)
143
150
  text + (amount > 1 ? 's' : '')
144
151
  end
152
+
153
+ def parameter_names_from_expression(expr)
154
+ if (name = expr.parameter_name)
155
+ [name] + parameter_names_from_method_calls(expr.try(:method_calls))
156
+ else
157
+ []
158
+ end
159
+ end
160
+
161
+ def parameter_names_from_method_calls(method_calls)
162
+ return [] unless method_calls
163
+
164
+ method_calls.flat_map do |mc|
165
+ mc.arguments.flat_map do |arg|
166
+ arg.is_a?(Expression) ? arg.all_substitution_parameter_names : []
167
+ end
168
+ end
169
+ end
145
170
  end
146
171
  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.pre.2"
5
5
  end
@@ -69,6 +69,11 @@ class ParameterSubstitution
69
69
  parse_expression(context).substitution_parameter_names
70
70
  end
71
71
 
72
+ def find_all_tokens(string_with_tokens, mapping: {}, context_overrides: {})
73
+ context = build_context(string_with_tokens, mapping, context_overrides)
74
+ parse_expression(context).all_substitution_parameter_names
75
+ end
76
+
72
77
  def find_formatters(string_with_tokens, mapping: {}, context_overrides: {})
73
78
  context = build_context(string_with_tokens, mapping, context_overrides)
74
79
  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.pre.2
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-18 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
@@ -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