Class: Chocomint::Tools::FileInfo

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

Overview

許可ディレクトリ内のパスのメタ情報 (存在・種別・サイズ) を JSON で返す。

Instance Method Summary collapse

Methods inherited from Base

#to_tool_definition

Constructor Details

#initialize(path_guard:) ⇒ FileInfo

Returns a new instance of FileInfo.



10
11
12
# File 'lib/chocomint/tools/file_info.rb', line 10

def initialize(path_guard:)
  @path_guard = path_guard
end

Instance Method Details

#call(args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chocomint/tools/file_info.rb', line 31

def call(args)
  measure do
    abs = @path_guard.resolve(args["path"])
    info = {
      "path" => args["path"],
      "exists" => File.exist?(abs),
      "type" => file_type(abs),
      "size" => (File.size(abs) if File.exist?(abs))
    }
    ok(stdout: JSON.generate(info))
  end
end

#descriptionObject



16
17
18
# File 'lib/chocomint/tools/file_info.rb', line 16

def description
  "指定パスの存在・種別 (file/directory)・サイズを JSON で返す。path は許可ディレクトリ内であること。"
end

#nameObject



14
# File 'lib/chocomint/tools/file_info.rb', line 14

def name = "file_info"

#schemaObject



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

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