Method: Dry::Files::MemoryFileSystem#chdir

Defined in:
lib/dry/files/memory_file_system.rb

#chdir(path, &blk) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Temporary changes the current working directory of the process to the given path and yield the given block.

The argument ‘path` is intended to be a directory.

Parameters:

  • path (String)

    the target directory

  • blk (Proc)

    the code to execute with the target directory

Raises:

Since:

  • 0.1.0



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/dry/files/memory_file_system.rb', line 179

def chdir(path, &blk)
  path = Path[path]
  directory = find(path)

  raise IOError, Errno::ENOENT.new(path.to_s) if directory.nil?
  raise IOError, Errno::ENOTDIR.new(path.to_s) unless directory.directory?

  current_root = @root
  @root = directory
  blk.call
ensure
  @root = current_root
end