Class: Chocomint::Tools::ListDir
- Defined in:
- lib/chocomint/tools/list_dir.rb
Overview
許可ディレクトリ内のエントリ一覧を改行区切りで stdout に返す。
Instance Method Summary collapse
- #call(args) ⇒ Object
- #description ⇒ Object
-
#initialize(path_guard:) ⇒ ListDir
constructor
A new instance of ListDir.
- #name ⇒ Object
- #schema ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(path_guard:) ⇒ ListDir
Returns a new instance of ListDir.
9 10 11 |
# File 'lib/chocomint/tools/list_dir.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 |
# File 'lib/chocomint/tools/list_dir.rb', line 30 def call(args) measure do abs = @path_guard.resolve(args["path"]) next fail(stderr: "no such directory: #{args['path']}") unless File.directory?(abs) entries = Dir.children(abs).sort ok(stdout: entries.join("\n")) end end |
#description ⇒ Object
15 16 17 |
# File 'lib/chocomint/tools/list_dir.rb', line 15 def description "指定ディレクトリのエントリ一覧を返す。path は許可ディレクトリ内であること。" end |
#name ⇒ Object
13 |
# File 'lib/chocomint/tools/list_dir.rb', line 13 def name = "list_dir" |
#schema ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chocomint/tools/list_dir.rb', line 19 def schema { "type" => "object", "properties" => { "path" => { "type" => "string" } }, "required" => %w[path], "additionalProperties" => false } end |