Sha256: 7f35c36588115f3c40528293c534312bd0653f621abe88edcadd0d03a0b8d23f

Contents?: true

Size: 1.82 KB

Versions: 32

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

# An in-memory file abstraction. Commonly used with Puppet::FileSystem::File#overlay
# @api private
class Puppet::FileSystem::MemoryFile
  attr_reader :path, :children

  def self.a_missing_file(path)
    new(path, :exist? => false, :executable? => false)
  end

  def self.a_missing_directory(path)
    new(path,
        :exist? => false,
        :executable? => false,
        :directory? => true)
  end

  def self.a_regular_file_containing(path, content)
    new(path, :exist? => true, :executable? => false, :content => content)
  end

  def self.an_executable(path)
    new(path, :exist? => true, :executable? => true)
  end

  def self.a_directory(path, children = [])
    new(path,
        :exist? => true,
        :executable? => true,
        :directory? => true,
        :children => children)
  end

  def self.a_symlink(target_path, source_path)
    new(target_path, :exist? => true, :symlink? => true, :source_path => source_path)
  end

  def initialize(path, properties)
    @path = path
    @properties = properties
    @children = (properties[:children] || []).collect do |child|
      child.duplicate_as(File.join(@path, child.path))
    end
  end

  def directory?; @properties[:directory?]; end
  def exist?; @properties[:exist?]; end
  def executable?; @properties[:executable?]; end
  def symlink?; @properties[:symlink?]; end
  def source_path; @properties[:source_path]; end

  def each_line(&block)
    handle.each_line(&block)
  end

  def handle
    raise Errno::ENOENT unless exist?

    StringIO.new(@properties[:content] || '')
  end

  def duplicate_as(other_path)
    self.class.new(other_path, @properties)
  end

  def absolute?
    Pathname.new(path).absolute?
  end

  def to_path
    path
  end

  def to_s
    to_path
  end

  def inspect
    "<Puppet::FileSystem::MemoryFile:#{self}>"
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/file_system/memory_file.rb
puppet-8.10.0-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.10.0-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.10.0-universal-darwin lib/puppet/file_system/memory_file.rb
puppet-8.9.0 lib/puppet/file_system/memory_file.rb
puppet-8.9.0-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.9.0-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.9.0-universal-darwin lib/puppet/file_system/memory_file.rb
puppet-8.8.1 lib/puppet/file_system/memory_file.rb
puppet-8.8.1-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.8.1-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.8.1-universal-darwin lib/puppet/file_system/memory_file.rb
puppet-8.7.0 lib/puppet/file_system/memory_file.rb
puppet-8.7.0-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.7.0-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.7.0-universal-darwin lib/puppet/file_system/memory_file.rb
puppet-8.6.0 lib/puppet/file_system/memory_file.rb
puppet-8.6.0-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.6.0-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-8.6.0-universal-darwin lib/puppet/file_system/memory_file.rb