Class: OmniAI::Tools::Disk::FileReplaceTool
- Defined in:
- lib/omniai/tools/disk/file_replace_tool.rb
Overview
Instance Method Summary collapse
Methods inherited from BaseTool
Constructor Details
This class inherits a constructor from OmniAI::Tools::Disk::BaseTool
Instance Method Details
#execute(old_text:, new_text:, path:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/omniai/tools/disk/file_replace_tool.rb', line 25 def execute(old_text:, new_text:, path:) @logger.info %(#{self.class.name}#execute old_text="#{old_text}" new_text="#{new_text}" path="#{path}") resolved = resolve!(path:) contents = File.read(resolved) modified = contents.gsub(old_text, new_text) File.write(resolved, modified) rescue StandardError => e @logger.error(e.) raise e end |