Class: RubyCoded::Tools::WriteFileTool
- Defined in:
- lib/ruby_coded/tools/write_file_tool.rb
Overview
Create a new file or overwrite an existing file with the given content
Constant Summary
Constants inherited from BaseTool
BaseTool::CONFIRM_RISK, BaseTool::DANGEROUS_RISK, BaseTool::SAFE_RISK
Instance Method Summary collapse
Methods inherited from BaseTool
Constructor Details
This class inherits a constructor from RubyCoded::Tools::BaseTool
Instance Method Details
#execute(path:, content:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_coded/tools/write_file_tool.rb', line 17 def execute(path:, content:) full_path = validate_path!(path) return full_path if full_path.is_a?(Hash) dir = File.dirname(full_path) FileUtils.mkdir_p(dir) unless File.directory?(dir) File.write(full_path, content) "File written: #{path} (#{content.bytesize} bytes)" rescue SystemCallError => e { error: "Failed to write #{path}: #{e.}" } end |