Class: RubyCoded::Tools::EditFileTool

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

Overview

Replace a specific text occurrence in an existing file (search and replace)

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:, old_text:, new_text:) ⇒ Object



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

def execute(path:, old_text:, new_text:)
  run_pipeline(path: path) do |full_path|
    next { error: "File not found: #{path}" } unless File.exist?(full_path)
    next { error: "Not a file: #{path}" } unless File.file?(full_path)

    apply_edit(path, full_path, old_text, new_text)
  end
end