lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-0.9.0 vs lib/buildmaster/cotta/in_memory_system.rb in BuildMaster-0.9.1

- old
+ new

@@ -12,15 +12,26 @@ @executed_commands = [] @content = "" @file_system = Hash.new @file_system[Pathname.new('/')] = DirectoryContent.new('/') @file_system[Pathname.new('.')] = DirectoryContent.new('.') + @output_map = Hash.new end def shell(command) @executed_commands.push(command) end + + def shell_output(command) + result = @output_map[command] + raise "#{command} not found in expectation" unless result + return result + end + + def output_for_command(command, output) + @output_map[command] = output + end def dir_exists?(pathname) content = path_content(pathname) return !content.nil? && content.directory? end @@ -43,19 +54,39 @@ file_content = retrieve_file_content(args[0], args[1]) return StringIO.new(file_content.content, *args[1, args.size - 1]) end def copy(source, target) + copy_file(source, target) + end + + def copy_file(source, target) file_content = retrieve_file_content(source, 'r').content create_file(target).content = file_content.clone end def move(source, target) + move_file(source, target) + end + + def move_file(source, target) copy(source, target) delete_file(source) end + def copy_dir(source, target) + mkdir(target) + path_content(source).children.each do |item| + item.copy_to_dir(self, source, target) + end + end + + def move_dir(source, target) + copy_dir(source, target) + delete_dir(source) + end + def delete_file(pathname) raise Errno::ENOENT.new(pathname) unless file_exists? pathname delete_entry(pathname) end @@ -85,10 +116,12 @@ return content end def create_file(pathname) content = FileContent.new(pathname.basename.to_s) + parent_dir = pathname.parent + path_content(parent_dir).add(content) @file_system[pathname] = content return content end def path_content(pathname) @@ -99,13 +132,11 @@ file_content = path_content(pathname) if (file_content.nil?) if (options =~ /r/) raise Errno::ENOENT.new(pathname) end - parent_dir = pathname.parent file_content = create_file(pathname) - path_content(parent_dir).add(file_content) end return file_content end def delete_entry(pathname) @@ -136,10 +167,16 @@ end def delete(name) @children.delete_if {|file_content| file_content.name == name} end + + def copy_to_dir(system, parent_dir, target_dir) + source_path = parent_dir.join(name) + target_path = target_dir.join(name) + system.copy_dir(source_path, target_path) + end end class FileContent attr_reader :name, :content attr_writer :content @@ -153,8 +190,14 @@ return true end def directory? return false + end + + def copy_to_dir(system, parent_dir, target_dir) + target_path = target_dir.join(name) + source_path = parent_dir.join(name) + system.copy_file(source_path, target_path) end end end \ No newline at end of file