Method: Puppet::Parser::TemplateWrapper#result

Defined in:
lib/vendor/puppet/parser/templatewrapper.rb

#result(string = nil) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/vendor/puppet/parser/templatewrapper.rb', line 80

def result(string = nil)
  if string
    self.string = string
    template_source = "inline template"
  else
    template_source = file
  end

  # Expose all the variables in our scope as instance variables of the
  # current object, making it possible to access them without conflict
  # to the regular methods.
  benchmark(:debug, "Bound template variables for #{template_source}") do
    scope.to_hash.each { |name, value|
      if name.kind_of?(String)
        realname = name.gsub(/[^\w]/, "_")
      else
        realname = name
      end
      instance_variable_set("@#{realname}", value)
    }
  end

  result = nil
  benchmark(:debug, "Interpolated template #{template_source}") do
    template = ERB.new(self.string, 0, "-")
    template.filename = file
    result = template.result(binding)
  end

  result
end