Sha256: 9a242a66693622210021b416012de1e06dc3eb85f1e12414518c520fbd4e91da

Contents?: true

Size: 1.54 KB

Versions: 58

Compression:

Stored size: 1.54 KB

Contents

# 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_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,
        :excutable? => true,
        :directory? => true,
        :children => children)
  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 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

  # Used by Ruby 1.8.7 file system abstractions when operating on Pathname like things.
  def to_str
    to_path
  end

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

Version data entries

58 entries across 58 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb
puppet-3.8.7 lib/puppet/file_system/memory_file.rb
puppet-3.8.7-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-3.8.7-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-3.8.6 lib/puppet/file_system/memory_file.rb
puppet-3.8.6-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb
puppet-3.8.6-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb
puppet-3.8.5 lib/puppet/file_system/memory_file.rb
puppet-3.8.5-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-3.8.5-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-3.8.4 lib/puppet/file_system/memory_file.rb
puppet-3.8.4-x86-mingw32 lib/puppet/file_system/memory_file.rb
puppet-3.8.4-x64-mingw32 lib/puppet/file_system/memory_file.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_file.rb