28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/parameter_substitution.rb', line 28
def evaluate(
input:,
mapping:,
required_parameters: [],
parameter_start: "<",
parameter_end: ">",
destination_encoding: :text,
allow_unknown_replacement_parameters: false,
allow_nil: false,
allow_unmatched_parameter_end: false
)
context = ParameterSubstitution::Context.new(
input: input,
mapping: mapping,
required_parameters: required_parameters,
parameter_start: parameter_start,
parameter_end: parameter_end,
destination_encoding: destination_encoding,
allow_unknown_replacement_parameters: allow_unknown_replacement_parameters,
allow_nil: allow_nil,
allow_unmatched_parameter_end: allow_unmatched_parameter_end
)
expression = parse_expression(context)
expression.validate
[expression.evaluate, expression.warnings, expression.parameter_and_method_warnings]
rescue ParameterSubstitution::ParseError => ex
[context.input, ex.message, expression&.parameter_and_method_warnings]
rescue => ex
raise SubstitutionError, "Error occurred while parameter substitution: #{ex.message}"
end
|