Class: RailsAiBridge::Tools::SearchCode::RipgrepSearch::CommandBuilder

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

Overview

Builds the CLI command string.

Constant Summary collapse

SECRET_EXCLUDES =

Extensions and globs that should never be searched (lowercase and uppercase variants).

%w[
  *.key *.KEY
  *.pem *.PEM
  *.p12 *.P12
  *.pfx *.PFX
  *.crt *.CRT
  .env .env.* .ENV .ENV.*
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.

Parameters:

  • params (Hash)

    search parameters with keys +:pattern+, +:search_path+, +:file_type+, +:max_results+



66
67
68
69
70
71
# File 'lib/rails_ai_bridge/tools/search_code/ripgrep_search.rb', line 66

def initialize(params)
  @pattern = params[:pattern]
  @path = params[:search_path]
  @file_type = params[:file_type]
  @max = params[:max_results]
end

Instance Method Details

#buildArray<String>

Builds the full ripgrep command array.

Returns:

  • (Array<String>)

    command tokens for +Open3.capture2+



76
77
78
79
80
81
82
# File 'lib/rails_ai_bridge/tools/search_code/ripgrep_search.rb', line 76

def build
  cmd = ['rg', '--no-heading', '--line-number', '--max-count', @max.to_s]
  cmd.concat(excluded_path_flags)
  cmd.concat(secret_exclude_flags)
  cmd.concat(file_type_filters)
  cmd.push(@pattern, @path)
end