Sha256: f1433be288bca5a6db1857ab52fe2b281fcb6aafcba70638fb259383556a3392

Contents?: true

Size: 1.46 KB

Versions: 96

Compression:

Stored size: 1.46 KB

Contents

class Puppet::FileSystem::MemoryImpl
  def initialize(*files)
    @files = files + all_children_of(files)
  end

  def expand_path(path, dir_string = nil)
    File.expand_path(path, dir_string)
  end

  def exist?(path)
    path.exist?
  end

  def directory?(path)
    path.directory?
  end

  def file?(path)
    path.file?
  end

  def executable?(path)
    path.executable?
  end

  def children(path)
    path.children
  end

  def each_line(path, &block)
    path.each_line(&block)
  end

  def pathname(path)
    find(path) || Puppet::FileSystem::MemoryFile.a_missing_file(path)
  end

  def basename(path)
    path.duplicate_as(File.basename(path_string(path)))
  end

  def path_string(object)
    object.path
  end

  def read(path, opts = {})
    handle = assert_path(path).handle
    handle.read
  end

  def read_preserve_line_endings(path)
    read(path)
  end

  def open(path, *args, &block)
    handle = assert_path(path).handle
    if block_given?
      yield handle
    else
      return handle
    end
  end

  def assert_path(path)
    if path.is_a?(Puppet::FileSystem::MemoryFile)
      path
    else
      find(path) or raise ArgumentError, "Unable to find registered object for #{path.inspect}"
    end
  end

  private

  def find(path)
    @files.find { |file| file.path == path }
  end

  def all_children_of(files)
    children = files.collect(&:children).flatten
    if children.empty?
      []
    else
      children + all_children_of(children)
    end
  end
end

Version data entries

96 entries across 96 versions & 2 rubygems

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