Sha256: 5beb105795d4d29f0be33b3514852323f3c54694bb16cbe858c6bd79584c13e2

Contents?: true

Size: 832 Bytes

Versions: 15

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

# Read a file and return its contents.
Puppet::Functions.create_function(:'file::read', Puppet::Functions::InternalFunction) do
  # @param filename Absolute path or Puppet file path.
  # @example Read a file from disk
  #   file::read('/tmp/i_dumped_this_here')
  # @example Read a file from the modulepath
  #   file::read('example/files/VERSION')
  dispatch :read do
    scope_param
    required_param 'String', :filename
    return_type 'String'
  end

  def read(scope, filename)
    found = Puppet::Parser::Files.find_file(filename, scope.compiler.environment)
    unless found && Puppet::FileSystem.exist?(found)
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::NO_SUCH_FILE_OR_DIRECTORY, file: filename
      )
    end

    File.read(found)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bolt-1.21.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.20.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.19.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.18.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.17.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.16.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.15.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.14.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.13.1 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.13.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.12.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.11.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.10.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.9.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.8.1 bolt-modules/file/lib/puppet/functions/file/read.rb