Class: Chocomint::Tools::DeleteFile

Inherits:
Base
  • Object
show all
Defined in:
lib/chocomint/tools/delete_file.rb

Overview

許可ディレクトリ内のファイルを削除する。ディレクトリは対象外。

Instance Method Summary collapse

Methods inherited from Base

#to_tool_definition

Constructor Details

#initialize(path_guard:) ⇒ DeleteFile

Returns a new instance of DeleteFile.



9
10
11
# File 'lib/chocomint/tools/delete_file.rb', line 9

def initialize(path_guard:)
  @path_guard = path_guard
end

Instance Method Details

#call(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/chocomint/tools/delete_file.rb', line 30

def call(args)
  measure do
    abs = @path_guard.resolve(args["path"])
    next fail(stderr: "no such file: #{args['path']}") unless File.exist?(abs)
    next fail(stderr: "not a file: #{args['path']}") unless File.file?(abs)

    File.delete(abs)
    ok(stdout: "deleted #{args['path']}")
  end
end

#descriptionObject



15
16
17
# File 'lib/chocomint/tools/delete_file.rb', line 15

def description
  "指定パスのファイルを削除する。path は許可ディレクトリ内であること。ディレクトリは削除しない。"
end

#nameObject



13
# File 'lib/chocomint/tools/delete_file.rb', line 13

def name = "delete_file"

#schemaObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/chocomint/tools/delete_file.rb', line 19

def schema
  {
    "type" => "object",
    "properties" => {
      "path" => { "type" => "string" }
    },
    "required" => %w[path],
    "additionalProperties" => false
  }
end