Module: Garcon::Interpolation

Extended by:
Interpolation
Included in:
Interpolation
Defined in:
lib/garcon/utility/interpolation.rb

Instance Method Summary collapse

Instance Method Details

#interpolate(item = self, parent = nil) ⇒ String

Interpolate provides a means of externally using Ruby string interpolation mechinism.

Examples:

node[:ldap][:basedir] = '/opt'
node[:ldap][:homedir] = '%{basedir}/openldap/slap/happy'

interpolate(node[:ldap])[:homedir]  # => "/opt/openldap/slap/happy"

Parameters:

  • item (String) (defaults to: self)

    The string to interpolate.

  • parent (String, Hash) (defaults to: nil)

    The string used for substitution.

Returns:

  • (String)

    The interpolated string.



44
45
46
47
# File 'lib/garcon/utility/interpolation.rb', line 44

def interpolate(item = self, parent = nil)
  item = render item, parent
  item.is_a?(Hash) ? ::Mash.new(item) : item
end