Class: RailsForge::Analyzers::ControllerAnalyzer
- Inherits:
-
BaseAnalyzer
- Object
- BaseAnalyzer
- RailsForge::Analyzers::ControllerAnalyzer
- Defined in:
- lib/railsforge/analyzers/controller_analyzer.rb
Overview
ControllerAnalyzer scans controllers for issues
Constant Summary collapse
- MAX_LINES =
Configuration thresholds
150- MAX_METHODS =
10
Class Method Summary collapse
-
.analyze(base_path = nil) ⇒ Array<Hash>
Analyze controllers.
-
.find_rails_app_path ⇒ Object
Find Rails app path.
-
.print_results(results) ⇒ Object
Print results.
Methods inherited from BaseAnalyzer
#analyze, #find_rails_app_path
Class Method Details
.analyze(base_path = nil) ⇒ Array<Hash>
Analyze controllers
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/railsforge/analyzers/controller_analyzer.rb', line 17 def self.analyze(base_path = nil) base_path ||= find_rails_app_path return [] unless base_path controllers_dir = File.join(base_path, "app", "controllers") return [] unless Dir.exist?(controllers_dir) results = [] Dir.glob(File.join(controllers_dir, "**", "*_controller.rb")).each do |file| next if file.end_with?("_application_controller.rb") content = File.read(file) lines = content.lines.count methods = content.scan(/def \w+/).count issues = [] issues << "Exceeds #{MAX_LINES} lines" if lines > MAX_LINES issues << "Has #{methods} methods (max: #{MAX_METHODS})" if methods > MAX_METHODS if issues.any? results << { file: File.basename(file), path: file, lines: lines, methods: methods, issues: issues } end end results end |
.find_rails_app_path ⇒ Object
Find Rails app path
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/railsforge/analyzers/controller_analyzer.rb', line 68 def self.find_rails_app_path path = Dir.pwd max_depth = 10 max_depth.times do return path if File.exist?(File.join(path, "config", "application.rb")) parent = File.dirname(path) break if parent == path path = parent end nil end |
.print_results(results) ⇒ Object
Print results
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/railsforge/analyzers/controller_analyzer.rb', line 51 def self.print_results(results) puts "\nController Analysis" puts "-" * 40 if results.empty? puts "✓ No issues found" return end results.each do |result| puts "⚠ #{result[:file]}" puts " Lines: #{result[:lines]}, Methods: #{result[:methods]}" result[:issues].each { |issue| puts " - #{issue}" } end end |