Class: Opto::Resolvers::Interpolate
- Inherits:
-
Opto::Resolver
- Object
- Opto::Resolver
- Opto::Resolvers::Interpolate
- Defined in:
- lib/opto/resolvers/interpolate.rb
Overview
Interpolates values from other options into a template string.
Example: from:
interpolate: mysql://admin:$mysql_admin_pass@mysql:1234/$mysql_db_name
Instance Attribute Summary
Attributes inherited from Opto::Resolver
Instance Method Summary collapse
Methods inherited from Opto::Resolver
for, inherited, #initialize, origin, #origin, #reset_tried, resolvers, #set_tried, #tried?, #try_resolve
Constructor Details
This class inherits a constructor from Opto::Resolver
Instance Method Details
#after ⇒ Object
29 30 31 |
# File 'lib/opto/resolvers/interpolate.rb', line 29 def after reset_tried end |
#resolve ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/opto/resolvers/interpolate.rb', line 15 def resolve raise TypeError, "String expected" unless hint.kind_of?(String) hint.gsub(/(?<!\$)\$(?!\$)\{?\w+\}?/) do |v| var = v.tr('${}', '') if option.group.nil? || option.group.option(var).nil? raise RuntimeError, "Variable #{var} not declared" end if option.value_of(var).nil? raise RuntimeError, "No value for #{var}, note that the order is meaningful" end option.value_of(var) end end |