Class: Chocomint::Tools::ReadFile
- Defined in:
- lib/chocomint/tools/read_file.rb
Overview
許可ディレクトリ内のファイルを読み、内容を stdout に返す。
Instance Method Summary collapse
- #call(args) ⇒ Object
- #description ⇒ Object
-
#initialize(path_guard:, max_file_bytes:) ⇒ ReadFile
constructor
A new instance of ReadFile.
- #name ⇒ Object
- #schema ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(path_guard:, max_file_bytes:) ⇒ ReadFile
Returns a new instance of ReadFile.
9 10 11 12 |
# File 'lib/chocomint/tools/read_file.rb', line 9 def initialize(path_guard:, max_file_bytes:) @path_guard = path_guard @max_file_bytes = max_file_bytes end |
Instance Method Details
#call(args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/chocomint/tools/read_file.rb', line 31 def call(args) measure do abs = @path_guard.resolve(args["path"]) next fail(stderr: "no such file: #{args['path']}") unless File.file?(abs) if File.size(abs) > @max_file_bytes next fail(stderr: "file exceeds max_file_bytes (#{@max_file_bytes})") end ok(stdout: File.read(abs)) end end |
#description ⇒ Object
16 17 18 |
# File 'lib/chocomint/tools/read_file.rb', line 16 def description "指定パスのファイル内容を読み取る。path は許可ディレクトリ内であること。" end |
#name ⇒ Object
14 |
# File 'lib/chocomint/tools/read_file.rb', line 14 def name = "read_file" |
#schema ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chocomint/tools/read_file.rb', line 20 def schema { "type" => "object", "properties" => { "path" => { "type" => "string" } }, "required" => %w[path], "additionalProperties" => false } end |