Class: RailsAiBridge::Tools::SearchCode::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/search_code/validator.rb

Overview

Validates search inputs for the SearchCode tool.

Instance Method Summary collapse

Constructor Details

#initialize(pattern, file_type, root, path) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • pattern (String)

    search pattern

  • file_type (String, nil)

    optional file extension filter

  • root (String)

    application root path

  • path (String, nil)

    optional subdirectory path



12
13
14
15
16
17
# File 'lib/rails_ai_bridge/tools/search_code/validator.rb', line 12

def initialize(pattern, file_type, root, path)
  @pattern = pattern
  @file_type = file_type
  @root = root
  @path = path
end

Instance Method Details

#validateHash, MCP::Tool::Response

Validates and normalizes all search parameters.

Returns:

  • (Hash, MCP::Tool::Response)

    normalized params hash on success, error response on failure



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_ai_bridge/tools/search_code/validator.rb', line 22

def validate
  pattern_error = validate_pattern_size
  return pattern_error if pattern_error

  type = validate_and_normalize_file_type
  return type if type.is_a?(MCP::Tool::Response)

  security = validate_path_security
  return security if security.is_a?(MCP::Tool::Response)

  { file_type: type, search_path: security }
end