Class: RobotLab::To::Tools::Write
- Defined in:
- lib/robot_lab/to/tools/write.rb
Overview
Create a NEW file with the given contents. Parent directories are created as needed. The WriteGuard refuses this on files that already exist (use Edit instead) — small models otherwise rewrite whole files and destroy content.
Instance Method Summary collapse
Methods inherited from FileTool
#name, name_segment, short_name
Instance Method Details
#execute(path:, content:) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/robot_lab/to/tools/write.rb', line 21 def execute(path:, content:, **) resolved = File.(path, Dir.pwd) FileUtils.mkdir_p(File.dirname(resolved)) File.write(resolved, content.to_s) "Wrote #{content.to_s.lines.size} lines to #{path}" rescue SystemCallError => e "Error writing #{path}: #{e.}" end |