Class: Brute::Tools::FSWrite
Instance Method Summary
collapse
Methods inherited from Brute::Tool
#call, description, #description, param, param_definitions, params, #params, #params_schema
Instance Method Details
#execute(file_path:, content:) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/brute/tools/fs_write.rb', line 19
def execute(file_path:, content:)
path = File.expand_path(file_path)
Brute::Tools::FS::FileMutationQueue.serialize(path) do
old_content = File.exist?(path) ? File.read(path) : ''
Brute::Tools::FS::SnapshotStore.save(path)
FileUtils.mkdir_p(File.dirname(path))
File.write(path, content)
diff = Brute::Diff.unified(old_content, content)
{ success: true, file_path: path, bytes: content.bytesize, diff: diff }
end
end
|
#name ⇒ Object
17
|
# File 'lib/brute/tools/fs_write.rb', line 17
def name; "write"; end
|