parameter_substitution 3.0.0.pre.0 → 3.0.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: b7d5937f29714849ed0f6dcb964e0976a010cf106cf0c7a3abc8fc431d93b770
4
- data.tar.gz: b5410f60e594f40f6becd805a050b0e385ad58f71e049a421b6a7c07f76d8542
3
+ metadata.gz: 470d5abf687490b1aa41c54794478f9c0ffa4fd904b360cab55b60351eb2e9f7
4
+ data.tar.gz: acda768f6ff4e072b6769cb4cbb3d82cf81951ce0cc9a210a5fc541f04e006a9
5
5
  SHA512:
6
- metadata.gz: 385b533cc23ad5c51c9e3e8de2aa4898617b375d1692523cd4f1c34df0a20256cb074e73fb7d5c7303b18540797164c58e2fca212392b35a74d685439c31c014
7
- data.tar.gz: 8b4f90595113426f82ca45c691056f0fcb602bdad90df6f0e15e7996edb0d2f60b3f09fc432a0defd023ef5a8f5ce048e6482b792340f29a1e0daa395c8afc46
6
+ metadata.gz: 360e3825227457357b8c4a244862f889171d2f4c369e82b3a2907f2d8114297da9094fb4914c20f8885b42f544daf6563e0075f8fc9f02a4071ac2fc0ebb0d79
7
+ data.tar.gz: c339269735f7ba01a811c068a06ac5bb8a4100848eca49cc01f5e8903854c8cca570def8233a6cc0ee464b9525724d3c580a9f10fe5ff8b360d32e2457356508
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParameterSubstitution
4
- VERSION = "3.0.0-0"
4
+ VERSION = "3.0.0-2"
5
5
  end
@@ -3,6 +3,7 @@
3
3
  # See lib/parameter_substitution/readme.md
4
4
 
5
5
  require 'active_support/all'
6
+ require 'set'
6
7
  require "parameter_substitution/context"
7
8
  require "parameter_substitution/parse_error"
8
9
  require "parameter_substitution/parser"
@@ -63,17 +64,17 @@ class ParameterSubstitution
63
64
  ParameterSubstitution.config = config
64
65
  end
65
66
 
66
- def find_tokens(string_with_tokens, mapping: {}, context_overrides: nil)
67
+ def find_tokens(string_with_tokens, mapping: {}, context_overrides: {})
67
68
  context = build_context(string_with_tokens, mapping, context_overrides)
68
69
  parse_expression(context).substitution_parameter_names
69
70
  end
70
71
 
71
- def find_formatters(string_with_tokens, mapping: {}, context_overrides: nil)
72
+ def find_formatters(string_with_tokens, mapping: {}, context_overrides: {})
72
73
  context = build_context(string_with_tokens, mapping, context_overrides)
73
74
  parse_expression(context).method_names
74
75
  end
75
76
 
76
- def find_warnings(string_with_tokens, mapping: {}, context_overrides: nil)
77
+ def find_warnings(string_with_tokens, mapping: {}, context_overrides: {})
77
78
  context = build_context(string_with_tokens, mapping, context_overrides)
78
79
  parse_expression(context).parameter_and_method_warnings || []
79
80
  end
@@ -83,15 +84,42 @@ class ParameterSubstitution
83
84
  # Build context with optional overrides
84
85
  # @param [String] string_with_tokens The input string containing tokens
85
86
  # @param [Hash] mapping The mapping of parameters to values
86
- # @param [Hash, nil] context_overrides Optional overrides for context attributes
87
+ # @param [Hash] context_overrides Optional overrides for context attributes
87
88
  # @return [ParameterSubstitution::Context] The constructed context
89
+ # @raise [ArgumentError] if context_overrides contains invalid keys
88
90
  def build_context(string_with_tokens, mapping, context_overrides)
91
+ validate_context_overrides!(context_overrides)
92
+
89
93
  base_options = {
90
94
  input: string_with_tokens,
91
95
  mapping: mapping
92
96
  }
93
97
 
94
- ParameterSubstitution::Context.new(**base_options.merge(context_overrides || {}))
98
+ ParameterSubstitution::Context.new(**context_overrides.merge(base_options))
99
+ end
100
+
101
+ # @param [Hash] context_overrides The overrides to validate
102
+ # @raise [ArgumentError] if context_overrides contains invalid keys
103
+ def validate_context_overrides!(context_overrides)
104
+ return if context_overrides.empty?
105
+
106
+ valid_keys = %i[
107
+ required_parameters
108
+ parameter_start
109
+ parameter_end
110
+ destination_encoding
111
+ allow_unknown_replacement_parameters
112
+ allow_nil
113
+ allow_unmatched_parameter_end
114
+ ].to_set
115
+
116
+ invalid_keys = context_overrides.keys.reject { |key| valid_keys.include?(key.to_sym) }
117
+
118
+ if invalid_keys.any?
119
+ invalid_keys_list = invalid_keys.join(", ")
120
+ valid_keys_list = valid_keys.sort.join(", ")
121
+ raise ArgumentError, "Invalid context_overrides keys: #{invalid_keys_list}. Valid keys are: #{valid_keys_list}"
122
+ end
95
123
  end
96
124
 
97
125
  def parse_expression(context)
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.0.0.pre.0
4
+ version: 3.0.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: 2025-11-15 00:00:00.000000000 Z
11
+ date: 2025-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport