Class: Aiko::Tools::WriteFile
- Inherits:
-
Base
- Object
- Base
- Aiko::Tools::WriteFile
show all
- Defined in:
- lib/aiko/tools/write_file.rb
Constant Summary
Constants inherited
from Base
Base::OUTPUT_LIMIT
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#approval_message(arguments) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/aiko/tools/write_file.rb', line 46
def approval_message(arguments)
path = resolve_path(arguments.fetch("path"))
content = arguments.fetch("content")
action = File.exist?(path) ? "上書き" : "新規作成"
preview = content.lines.first(5).join
"write_file: #{arguments["path"]} を#{action}します(#{content.bytesize} bytes)\n--- 内容(先頭5行) ---\n#{preview}"
end
|
#call(arguments) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/aiko/tools/write_file.rb', line 34
def call(arguments)
path = resolve_path(arguments.fetch("path"))
content = arguments.fetch("content")
FileUtils.mkdir_p(File.dirname(path))
File.write(path, content)
"Wrote #{content.bytesize} bytes to #{arguments["path"]}"
end
|
#description ⇒ Object
12
13
14
15
|
# File 'lib/aiko/tools/write_file.rb', line 12
def description
"Create a new file or overwrite an existing file with the given content. " \
"Parent directories are created automatically."
end
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/aiko/tools/write_file.rb', line 17
def input_schema
{
"type" => "object",
"properties" => {
"path" => {
"type" => "string",
"description" => "File path relative to the working directory"
},
"content" => {
"type" => "string",
"description" => "Full content to write to the file"
}
},
"required" => %w[path content]
}
end
|
#name ⇒ Object
8
9
10
|
# File 'lib/aiko/tools/write_file.rb', line 8
def name
"write_file"
end
|
#requires_approval?(_arguments) ⇒ Boolean
42
43
44
|
# File 'lib/aiko/tools/write_file.rb', line 42
def requires_approval?(_arguments)
true
end
|