Class: Kreator::Tools::Find
- Inherits:
-
Object
- Object
- Kreator::Tools::Find
- Defined in:
- lib/kreator/tools/find.rb
Constant Summary collapse
- DEFAULT_MAX_RESULTS =
200
Instance Method Summary collapse
Instance Method Details
#call(args:, context:, signal:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kreator/tools/find.rb', line 30 def call(args:, context:, signal:) root = allowed_path(args.fetch("path", "."), context) name_pattern = args["name"] type = args.fetch("type", "any") include_hidden = args.fetch("include_hidden", false) max_results = args.fetch("max_results", DEFAULT_MAX_RESULTS) matches = [] each_path(root, include_hidden) do |path| context.ensure_not_cancelled!(signal) next unless type_match?(path, type) next unless name_match?(path, name_pattern) matches << relative_path(path, root) return result(root, matches, max_results) if matches.length > max_results end result(root, matches, max_results) end |
#description ⇒ Object
12 13 14 |
# File 'lib/kreator/tools/find.rb', line 12 def description "Find files and directories by name under an allowed path without shell predicates." end |
#name ⇒ Object
8 9 10 |
# File 'lib/kreator/tools/find.rb', line 8 def name "find" end |
#schema ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kreator/tools/find.rb', line 16 def schema { "type" => "object", "additionalProperties" => false, "properties" => { "path" => { "type" => "string", "minLength" => 1 }, "name" => { "type" => "string", "minLength" => 1 }, "type" => { "type" => "string", "enum" => %w[file directory any] }, "include_hidden" => { "type" => "boolean" }, "max_results" => { "type" => "integer", "minimum" => 1 } } } end |