Class: RubyCoded::Tools::DeletePathTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/ruby_coded/tools/delete_path_tool.rb

Overview

Delete a file or an empty directory at the given path

Constant Summary

Constants inherited from BaseTool

BaseTool::CONFIRM_RISK, BaseTool::DANGEROUS_RISK, BaseTool::SAFE_RISK

Instance Method Summary collapse

Methods inherited from BaseTool

#initialize

Constructor Details

This class inherits a constructor from RubyCoded::Tools::BaseTool

Instance Method Details

#execute(path:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_coded/tools/delete_path_tool.rb', line 17

def execute(path:)
  full_path = validate_path!(path)
  return full_path if full_path.is_a?(Hash)
  return { error: "Path not found: #{path}" } unless File.exist?(full_path)
  return { error: "Cannot delete the project root" } if full_path == @project_root

  perform_delete(path, full_path)
rescue SystemCallError => e
  { error: "Failed to delete #{path}: #{e.message}" }
end