Class: RailsAiBridge::Tools::SearchCode::RubySearch::FileProcessor
- Inherits:
-
Object
- Object
- RailsAiBridge::Tools::SearchCode::RubySearch::FileProcessor
- Defined in:
- lib/rails_ai_bridge/tools/search_code/ruby_search.rb
Overview
Encapsulates file-level search logic.
Constant Summary collapse
- SECRET_EXTENSIONS =
%w[.key .pem .p12 .pfx .crt].freeze
Class Method Summary collapse
-
.secret_file?(basename) ⇒ Boolean
Checks if a filename matches secret file patterns (case-insensitive .env and common key extensions).
Instance Method Summary collapse
-
#initialize(regex, results, max_results, root) ⇒ FileProcessor
constructor
A new instance of FileProcessor.
-
#process(file) ⇒ :full?
Processes a single file, collecting matching lines into results.
Constructor Details
#initialize(regex, results, max_results, root) ⇒ FileProcessor
Returns a new instance of FileProcessor.
19 20 21 22 23 24 |
# File 'lib/rails_ai_bridge/tools/search_code/ruby_search.rb', line 19 def initialize(regex, results, max_results, root) @regex = regex @results = results @max_results = max_results @root = root end |
Class Method Details
.secret_file?(basename) ⇒ Boolean
Checks if a filename matches secret file patterns (case-insensitive .env and common key extensions).
@param basename [String] file basename
@return [Boolean] +true+ if the file looks like a secret file
46 47 48 49 50 51 |
# File 'lib/rails_ai_bridge/tools/search_code/ruby_search.rb', line 46 def self.secret_file?(basename) normalized = basename.downcase return true if normalized.start_with?('.env') SECRET_EXTENSIONS.any? { |ext| normalized.end_with?(ext) } end |
Instance Method Details
#process(file) ⇒ :full?
Processes a single file, collecting matching lines into results.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rails_ai_bridge/tools/search_code/ruby_search.rb', line 30 def process(file) return if skip_file?(file) relative = file.sub("#{@root}/", '') File.readlines(file).each_with_index do |line, idx| next unless line.match?(@regex) @results << { file: relative, line_number: idx + 1, content: line } return :full if @results.size >= @max_results end end |