Class: Chocomint::Tools::DeleteFile
- Defined in:
- lib/chocomint/tools/delete_file.rb
Overview
許可ディレクトリ内のファイルを削除する。ディレクトリは対象外。
Instance Method Summary collapse
- #call(args) ⇒ Object
- #description ⇒ Object
-
#initialize(path_guard:) ⇒ DeleteFile
constructor
A new instance of DeleteFile.
- #name ⇒ Object
- #schema ⇒ Object
Methods inherited from Base
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 |
#description ⇒ Object
15 16 17 |
# File 'lib/chocomint/tools/delete_file.rb', line 15 def description "指定パスのファイルを削除する。path は許可ディレクトリ内であること。ディレクトリは削除しない。" end |
#name ⇒ Object
13 |
# File 'lib/chocomint/tools/delete_file.rb', line 13 def name = "delete_file" |
#schema ⇒ Object
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 |