Sha256: f0ff7074630636dffe83d80fb338f3cfec2017fa71c39ff235233d64bab30212

Contents?: true

Size: 1.3 KB

Versions: 43

Compression:

Stored size: 1.3 KB

Contents

class Puppet::FileSystem::MemoryImpl
  def initialize(*files)
    @files = files + all_children_of(files)
  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)
    handle = assert_path(path).handle
    handle.read
  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

43 entries across 43 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.8.0 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.7.3 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-retrospec-0.7.2 vendor/gems/puppet-3.7.3/lib/puppet/file_system/memory_impl.rb
puppet-4.0.0 lib/puppet/file_system/memory_impl.rb
puppet-4.0.0-x86-mingw32 lib/puppet/file_system/memory_impl.rb
puppet-4.0.0-x64-mingw32 lib/puppet/file_system/memory_impl.rb
puppet-3.7.5 lib/puppet/file_system/memory_impl.rb
puppet-3.7.5-x86-mingw32 lib/puppet/file_system/memory_impl.rb
puppet-3.7.5-x64-mingw32 lib/puppet/file_system/memory_impl.rb
puppet-4.0.0.rc1 lib/puppet/file_system/memory_impl.rb
puppet-4.0.0.rc1-x86-mingw32 lib/puppet/file_system/memory_impl.rb
puppet-4.0.0.rc1-x64-mingw32 lib/puppet/file_system/memory_impl.rb