Class: Chocomint::Tools::MakeDir

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

Overview

許可ディレクトリ内にディレクトリを作成する (親も含め mkdir_p)。

Instance Method Summary collapse

Methods inherited from Base

#to_tool_definition

Constructor Details

#initialize(path_guard:) ⇒ MakeDir

Returns a new instance of MakeDir.



9
10
11
# File 'lib/chocomint/tools/make_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
39
40
41
# File 'lib/chocomint/tools/make_dir.rb', line 30

def call(args)
  measure do
    abs = @path_guard.resolve(args["path"])
    if File.file?(abs)
      next fail(stderr: "a file already exists at #{args['path']}")
    end

    require "fileutils"
    FileUtils.mkdir_p(abs)
    ok(stdout: "created directory #{args['path']}")
  end
end

#descriptionObject



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

def description
  "指定パスにディレクトリを作成する (親ディレクトリも作成)。path は許可ディレクトリ内であること。"
end

#nameObject



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

def name = "make_dir"

#schemaObject



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

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