class Opto::Resolvers::Interpolate

Interpolates values from other options into a template string.

Example: from:

interpolate: mysql://admin:$mysql_admin_pass@mysql:1234/$mysql_db_name

Public Instance Methods

resolve() click to toggle source
# 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('${}', '')

    raise RuntimeError, "Variable #{var} not declared" if option.group.nil?
    opt = option.group.option(var)
    raise RuntimeError, "Variable #{var} not declared" if opt.nil?
    value = opt.value
    raise RuntimeError, "No value for #{var}, note that the order is meaningful" if value.nil?
    value
  end
end