Sha256: 9761497cb936444c4ad0a726ec6a8c0c2178a814462d1961eab15c6a457f914c

Contents?: true

Size: 1.85 KB

Versions: 45

Compression:

Stored size: 1.85 KB

Contents

#
# interpolate.rb
#
# Interpolate values from one hash to another for configuration injection.
#
module Puppet::Parser::Functions
  newfunction(:interpolate, :type => :rvalue, :doc => <<-EOS
This function interpolates values from one hash to another for configuration injections.
    EOS
) do |args|
    
    value = nil
    CORL.run do
      raise(Puppet::ParseError, "interpolate(): Define at least a property name with optional source configurations " +
        "given (#{args.size} for 2)") if args.size < 1
      
      value   = args[0]
      data    = ( args.size > 1 ? args[1] : {} )
      options = ( args.size > 2 ? args[2] : {} )
      
      module_name = parent_module_name
      contexts    = [ :data, :interpolate ]
      
      if module_name
        config = CORL::Config.init(options, contexts, module_name)  
      else
        config = CORL::Config.init_flat(options, contexts)
      end
      
      value = CORL::Util::Data.interpolate(value, data, config.export)
      
      if config.get(:debug, false)
        display_name = module_name ? module_name : "toplevel"
              
        CORL.ui.info("\n", { :prefix => false })
        CORL.ui_group(CORL::Util::Console.cyan("#{display_name} interpolation")) do |ui|
          ui.info("-----------------------------------------------------")
        
          source_dump        = CORL::Util::Console.blue(CORL::Util::Data.to_json(args[0], true))
          interpolation_data = CORL::Util::Console.grey(CORL::Util::Data.to_json(data, true))
          value_dump         = CORL::Util::Console.green(CORL::Util::Data.to_json(value, true))       
        
          ui.info("Original:\n#{source_dump}")
          ui.info("Interpolation data:\n#{interpolation_data}")
          ui.info("Interpolated:\n#{value_dump}")
          ui.info("\n", { :prefix => false }) 
        end
      end
    end
    return value
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
corl-0.5.18 lib/puppet/parser/functions/interpolate.rb
corl-0.5.17 lib/puppet/parser/functions/interpolate.rb
corl-0.5.16 lib/puppet/parser/functions/interpolate.rb
corl-0.5.15 lib/puppet/parser/functions/interpolate.rb
corl-0.5.14 lib/puppet/parser/functions/interpolate.rb
corl-0.5.13 lib/puppet/parser/functions/interpolate.rb
corl-0.5.12 lib/puppet/parser/functions/interpolate.rb
corl-0.5.11 lib/puppet/parser/functions/interpolate.rb
corl-0.5.10 lib/puppet/parser/functions/interpolate.rb
corl-0.5.9 lib/puppet/parser/functions/interpolate.rb
corl-0.5.8 lib/puppet/parser/functions/interpolate.rb
corl-0.5.7 lib/puppet/parser/functions/interpolate.rb
corl-0.5.6 lib/puppet/parser/functions/interpolate.rb
corl-0.5.5 lib/puppet/parser/functions/interpolate.rb
corl-0.5.4 lib/puppet/parser/functions/interpolate.rb
corl-0.5.3 lib/puppet/parser/functions/interpolate.rb
corl-0.5.2 lib/puppet/parser/functions/interpolate.rb
corl-0.5.1 lib/puppet/parser/functions/interpolate.rb
corl-0.5.0 lib/puppet/parser/functions/interpolate.rb
corl-0.4.29 lib/puppet/parser/functions/interpolate.rb