All pastes #558444 Raw Edit

Someone

public text v1 · immutable
·published 2007-06-11 11:55 UTC
rendered paste body
#!/usr/bin/ruby

module Puppet::Parser::Functions
  newfunction(:concatenate, :type => :rvalue) do |args|
        directory = args[0]
        # optional argument to add include messages
        # comment = args[1]

        # initialize content
        content = ""

        Dir[ "#{directory}/*" ].each do |file|
                if file =~ /\d\d_\S+/
                        # get class name
                        file_class = file.sub(/.*\d\d_(\S+)/,'\1')

                        # check if class is defined
                        method = Puppet::Parser::Functions.function(:defined)
                        if send(method,file_class)

                                # include file
                                File.open(file, "r") do |infile|
                                        while (line = infile.gets)
                                                content << "#{line}"
                                        end
                                end
                        else
                                puts "I: Class #{file_class} is not defined. Not including #{file}"
                        end
                else
                        puts "W: #{file} does not have a correct name and will not be included."
                end
        end
        return content
  end
end