Class: RubyCoded::Tools::WriteFileTool

Inherits:
BaseTool
  • Object
show all
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

#initialize

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
# File 'lib/ruby_coded/tools/write_file_tool.rb', line 17

def execute(path:, content:)
  run_pipeline(path: path) do |full_path|
    dir = File.dirname(full_path)
    FileUtils.mkdir_p(dir) unless File.directory?(dir)

    File.write(full_path, content)
    "File written: #{path} (#{content.bytesize} bytes)"
  end
end