Class: RailsMcpInsight::Analyzers::ControllerAnalyzer
- Inherits:
-
Object
- Object
- RailsMcpInsight::Analyzers::ControllerAnalyzer
- Defined in:
- lib/rails_mcp_insight/analyzers/controller_analyzer.rb
Overview
Analyzes Rails controller files to extract actions, filters, strong params, rescue handlers, and inheritance chains.
Instance Method Summary collapse
-
#analyze(controller_name) ⇒ Object
Analyze a specific controller.
-
#initialize(config, ast_parser: AstParser.new) ⇒ ControllerAnalyzer
constructor
A new instance of ControllerAnalyzer.
Constructor Details
#initialize(config, ast_parser: AstParser.new) ⇒ ControllerAnalyzer
Returns a new instance of ControllerAnalyzer.
8 9 10 11 |
# File 'lib/rails_mcp_insight/analyzers/controller_analyzer.rb', line 8 def initialize(config, ast_parser: AstParser.new) @config = config @ast_parser = ast_parser end |
Instance Method Details
#analyze(controller_name) ⇒ Object
Analyze a specific controller
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_mcp_insight/analyzers/controller_analyzer.rb', line 14 def analyze(controller_name) file_path = find_controller_file(controller_name) return nil unless file_path parsed = @ast_parser.parse_file(file_path) return nil unless parsed { name: controller_name, file: relative_path(file_path), parent_class: parsed.classes.first&.parent || "ApplicationController", actions: extract_actions(parsed), before_actions: extract_filters(parsed, "before_action"), after_actions: extract_filters(parsed, "after_action"), around_actions: extract_filters(parsed, "around_action"), skip_before_actions: extract_filters(parsed, "skip_before_action"), strong_params: extract_strong_params(file_path), rescue_handlers: extract_rescue_handlers(parsed), concerns: parsed.includes.map { |i| i[:module] }, private_methods: parsed.methods.select { |m| m.visibility == :private }.map(&:name), constants: parsed.constants.map { |c| { name: c[:name], value: c[:value] } } } end |