Class: QueryGuard::CLI::Commands::Analyze
- Inherits:
-
QueryGuard::CLI::Command
- Object
- QueryGuard::CLI::Command
- QueryGuard::CLI::Commands::Analyze
- Defined in:
- lib/query_guard/cli/commands/analyze.rb
Overview
Analyzes queries and migrations, printing detailed results
Instance Method Summary collapse
Methods inherited from QueryGuard::CLI::Command
Constructor Details
This class inherits a constructor from QueryGuard::CLI::Command
Instance Method Details
#execute ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/query_guard/cli/commands/analyze.rb', line 8 def execute unless path_exists? puts "Error: Path does not exist: #{path_absolute}" exit 1 end # Skip progress output if JSON format is being used unless [:json] || [:format] == 'json' puts "Analyzing: #{path_absolute}" # Show database context adapter = get_database_adapter if adapter puts "Database context: Connected (accurate severity)\n" else puts "Database context: Not available (conservative estimates)" puts " For more accurate results, run: DATABASE_URL=... queryguard analyze\n" end puts "(This may take a moment...)\n" end # Find and analyze migration files migration_files = find_migration_files(@path) if migration_files.any? puts " Found #{migration_files.length} migration files" unless [:json] || [:format] == 'json' findings = analyze_migrations(migration_files) else findings = [] end # Format and print results if findings.any? @formatter.print_findings(findings, "Migration Risk Analysis Results", 'analyze', @path) else puts "\n✅ No issues found in migrations!\n" unless [:json] || [:format] == 'json' end # Exit with success (analyze doesn't fail on findings) 0 end |