Class: RailsOpenapiGen::Parsers::ControllerParser
- Inherits:
-
Object
- Object
- RailsOpenapiGen::Parsers::ControllerParser
- Defined in:
- lib/rails-openapi-gen/parsers/controller_parser.rb
Defined Under Namespace
Classes: ActionMethodProcessor
Instance Attribute Summary collapse
-
#route ⇒ Object
readonly
Returns the value of attribute route.
-
#template_processor ⇒ Object
readonly
Returns the value of attribute template_processor.
Instance Method Summary collapse
-
#initialize(route, template_processor: nil) ⇒ ControllerParser
constructor
Initializes controller parser with route information and template processor.
-
#parse ⇒ Hash
Parses controller to find action method and response template.
Constructor Details
#initialize(route, template_processor: nil) ⇒ ControllerParser
Initializes controller parser with route information and template processor
14 15 16 17 18 19 |
# File 'lib/rails-openapi-gen/parsers/controller_parser.rb', line 14 def initialize(route, template_processor: nil) @route = route @template_processor = template_processor || RailsOpenapiGen::Parsers::TemplateProcessors::JbuilderTemplateProcessor.new( route[:controller], route[:action] ) end |
Instance Attribute Details
#route ⇒ Object (readonly)
Returns the value of attribute route.
9 10 11 |
# File 'lib/rails-openapi-gen/parsers/controller_parser.rb', line 9 def route @route end |
#template_processor ⇒ Object (readonly)
Returns the value of attribute template_processor.
9 10 11 |
# File 'lib/rails-openapi-gen/parsers/controller_parser.rb', line 9 def template_processor @template_processor end |
Instance Method Details
#parse ⇒ Hash
Parses controller to find action method and response template
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rails-openapi-gen/parsers/controller_parser.rb', line 23 def parse controller_path = find_controller_file return {} unless controller_path content = File.read(controller_path) ast = Parser::CurrentRuby.parse(content) action_node = find_action_method(ast) return {} unless action_node template_path = extract_template_path(action_node) parameters = extract_parameters_from_comments(content, action_node) { controller_path: controller_path, jbuilder_path: template_path, # Keep existing key name for backward compatibility action: route[:action], parameters: parameters } end |