Sha256: d24ace7ff8674fa5be07247057e87de974fa2578b936ca048ed4b0c63c82c56d

Contents?: true

Size: 1.06 KB

Versions: 179

Compression:

Stored size: 1.06 KB

Contents

require 'puppet/file_system'

Puppet::Parser::Functions::newfunction(
  :file, :arity => -2, :type => :rvalue,
  :doc => "Loads a file from a module and returns its contents as a string.

  The argument to this function should be a `<MODULE NAME>/<FILE>`
  reference, which will load `<FILE>` from a module's `files`
  directory. (For example, the reference `mysql/mysqltuner.pl` will load the
  file `<MODULES DIRECTORY>/mysql/files/mysqltuner.pl`.)

  This function can also accept:

  * An absolute path, which can load a file from anywhere on disk.
  * Multiple arguments, which will return the contents of the **first** file
  found, skipping any files that don't exist.
  "
) do |vals|
    path = nil
    vals.each do |file|
      found = Puppet::Parser::Files.find_file(file, compiler.environment)
      if found && Puppet::FileSystem.exist?(found)
        path = found
        break
      end
    end

    if path
      Puppet::FileSystem.read_preserve_line_endings(path)
    else
      raise Puppet::ParseError, "Could not find any files from #{vals.join(", ")}"
    end
end

Version data entries

179 entries across 179 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/parser/functions/file.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/parser/functions/file.rb
puppet-4.10.12 lib/puppet/parser/functions/file.rb
puppet-4.10.12-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.12-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.12-universal-darwin lib/puppet/parser/functions/file.rb
puppet-4.10.11 lib/puppet/parser/functions/file.rb
puppet-4.10.11-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.11-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.11-universal-darwin lib/puppet/parser/functions/file.rb
puppet-4.10.10 lib/puppet/parser/functions/file.rb
puppet-4.10.10-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.10-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.10-universal-darwin lib/puppet/parser/functions/file.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/parser/functions/file.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/parser/functions/file.rb
puppet-4.10.9 lib/puppet/parser/functions/file.rb
puppet-4.10.9-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.9-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-4.10.9-universal-darwin lib/puppet/parser/functions/file.rb