Class: Bora::ParameterResolver
- Inherits:
-
Object
- Object
- Bora::ParameterResolver
- Defined in:
- lib/bora/parameter_resolver.rb
Constant Summary collapse
- UnresolvedSubstitutionError =
Class.new(StandardError)
- PLACEHOLDER_REGEX =
Regular expression that can match placeholders nested to two levels. For example it will match: “$foo-${bar}”. See stackoverflow.com/questions/17759004/how-to-match-string-within-parentheses-nested-in-java
/\${([^{}]*|{[^{}]*})*}/
Instance Method Summary collapse
-
#initialize(stack) ⇒ ParameterResolver
constructor
A new instance of ParameterResolver.
- #resolve(params) ⇒ Object
Constructor Details
#initialize(stack) ⇒ ParameterResolver
Returns a new instance of ParameterResolver.
13 14 15 16 17 |
# File 'lib/bora/parameter_resolver.rb', line 13 def initialize(stack) @stack = stack @loader = ParameterResolverLoader.new @resolver_cache = {} end |
Instance Method Details
#resolve(params) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bora/parameter_resolver.rb', line 19 def resolve(params) unresolved_placeholders_still_remain = true while unresolved_placeholders_still_remain unresolved_placeholders_still_remain = false placeholders_were_substituted = false params.each do |k, v| resolved_value = process_param_substitutions(v, params) unresolved_placeholders_still_remain ||= unresolved_placeholder?(resolved_value) placeholders_were_substituted ||= resolved_value != v params[k] = resolved_value end if unresolved_placeholders_still_remain && !placeholders_were_substituted raise UnresolvedSubstitutionError, "Parameter substitutions could not be resolved:\n#{unresolved_placeholders_as_string(params)}" end end params end |