module Aruba::Api::Core
def cd(dir, &block)
- Example: Run code in directory -
Example: Move up -
Example: Normal directory -
Parameters:
-
dir(String) --
def cd(dir, &block) if block begin unless Aruba.platform.directory?(expand_path(dir)) raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." end old_directory = expand_path(".") aruba.current_directory << dir new_directory = expand_path(".") aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory) old_dir = Aruba.platform.getwd real_new_directory = File.expand_path(aruba.current_directory, aruba.root_directory) Aruba.platform.chdir real_new_directory result = with_environment( "OLDPWD" => old_dir, "PWD" => real_new_directory, &block ) ensure aruba.current_directory.pop Aruba.platform.chdir old_dir end return result end unless Aruba.platform.directory?(expand_path(dir)) raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." end old_directory = expand_path(".") aruba.current_directory << dir new_directory = expand_path(".") aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory) self end