parameter_substitution 3.0.0.pre.1 → 3.0.0.pre.3

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: ffc3265d1621830cdaed145097ef5b3d5f1b565112e761428128e60a41ec5ea2
4
- data.tar.gz: 84a25b5cdb7be43c5cb1e8391bdfa00fbfdd7802470c26d013b56363620c0a8b
3
+ metadata.gz: d4094f66f84b7cc0e556405a534d71614017c7d0a0ae5dd81d9684fb795062a3
4
+ data.tar.gz: f6156ebd337691d09ae23c287f4433121b83f1d1d624b9341629770f665ad48f
5
5
  SHA512:
6
- metadata.gz: cfcc848d6aa17e0508123d4ec52b516ce02e971a4111fbf56be893168487612a8ef3179b798dcca80ee7d961f5f89f50a188ddfa82156f5ec36cc27440e81a77
7
- data.tar.gz: 7dfda5d74dc1863861fd451a20e80d1f4d73f9d28e98e2b16c8dac2688840506c0eec5c86c79cbd2eca10b95f9bd4230bbd37932004380d033c83e28e45ab0a1
6
+ metadata.gz: 07e273978a485f05fe241fc1e999f40f8ae0310f71001a9803a86bbd0e6e1fc6641d9f8db8d593038ac9b6a0db8a978987fd7aa65aac189183340b39ade3ad09
7
+ data.tar.gz: ea5f719ad4adeb892c2dc5b0ea02521983e5eebef22d200b47c2d528fc29225520cc1417f0be8d4ce3dec6b488dec47158ebc07d09026ffbce1855c1d217d8ff
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParameterSubstitution
4
- VERSION = "3.0.0-1"
4
+ VERSION = "3.0.0-3"
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,38 +64,64 @@ 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
80
81
 
81
82
  private
82
83
 
84
+ VALID_CONTEXT_OVERRIDE_KEYS = %i[
85
+ required_parameters
86
+ parameter_start
87
+ parameter_end
88
+ destination_encoding
89
+ allow_unknown_replacement_parameters
90
+ allow_nil
91
+ allow_unmatched_parameter_end
92
+ ].to_set
93
+ private_constant :VALID_CONTEXT_OVERRIDE_KEYS
94
+
83
95
  # Build context with optional overrides
84
96
  # @param [String] string_with_tokens The input string containing tokens
85
97
  # @param [Hash] mapping The mapping of parameters to values
86
- # @param [Hash, nil] context_overrides Optional overrides for context attributes
98
+ # @param [Hash] context_overrides Optional overrides for context attributes
87
99
  # @return [ParameterSubstitution::Context] The constructed context
100
+ # @raise [ArgumentError] if context_overrides contains invalid keys
88
101
  def build_context(string_with_tokens, mapping, context_overrides)
89
- override_options = context_overrides || {}
102
+ validate_context_overrides!(context_overrides)
103
+
90
104
  base_options = {
91
105
  input: string_with_tokens,
92
106
  mapping: mapping
93
107
  }
94
108
 
95
- ParameterSubstitution::Context.new(**override_options.merge(base_options))
109
+ ParameterSubstitution::Context.new(**context_overrides.merge(base_options))
96
110
  end
97
111
 
112
+ # @param [Hash] context_overrides The overrides to validate
113
+ # @raise [ArgumentError] if context_overrides contains invalid keys
114
+ def validate_context_overrides!(context_overrides)
115
+ return if context_overrides.empty?
116
+
117
+ invalid_keys = context_overrides.keys.reject { |key| VALID_CONTEXT_OVERRIDE_KEYS.include?(key.to_sym) }
118
+
119
+ if invalid_keys.any?
120
+ invalid_keys_list = invalid_keys.join(", ")
121
+ valid_keys_list = VALID_CONTEXT_OVERRIDE_KEYS.sort.join(", ")
122
+ raise ArgumentError, "Invalid context_overrides keys: #{invalid_keys_list}. Valid keys are: #{valid_keys_list}"
123
+ end
124
+ end
98
125
 
99
126
  def parse_expression(context)
100
127
  cst = ParameterSubstitution::Parser.new(
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.1
4
+ version: 3.0.0.pre.3
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-17 00:00:00.000000000 Z
11
+ date: 2025-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport