Class: RailsApiDocs::Inspectors::ControllerInspector
- Inherits:
-
Object
- Object
- RailsApiDocs::Inspectors::ControllerInspector
- Defined in:
- lib/rails-api-docs/inspectors/controller_inspector.rb
Overview
Walks a controller file via Prism and returns the list of attribute names declared in any ‘params.require(:X).permit(…)` (or `params.permit(…)`) call inside the file.
This is a deliberately coarse pass — we don’t try to map a permit call back to a specific action. In typical Rails controllers strong params live in a single shared ‘*_params` method used by both create and update, so the flat list of permitted attributes is enough for documentation purposes.
Limitations (Phase 5):
- Nested permits (`permit(items: [:name])`) — only top-level scalar
keys are extracted; the nested array is ignored.
- Method-call args inside permit (e.g. `permit(*PERMITTED)`) — not
resolved; only literal symbols/strings are picked up.
Defined Under Namespace
Classes: PermitVisitor
Instance Method Summary collapse
- #call ⇒ Object
- #file_path ⇒ Object
-
#initialize(controller:, root: nil) ⇒ ControllerInspector
constructor
A new instance of ControllerInspector.
Constructor Details
#initialize(controller:, root: nil) ⇒ ControllerInspector
Returns a new instance of ControllerInspector.
23 24 25 26 |
# File 'lib/rails-api-docs/inspectors/controller_inspector.rb', line 23 def initialize(controller:, root: nil) @controller = controller @root = root || (defined?(Rails) && Rails.root ? Rails.root.to_s : ".") end |
Instance Method Details
#call ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/rails-api-docs/inspectors/controller_inspector.rb', line 28 def call return [] unless File.exist?(file_path) result = Prism.parse_file(file_path) visitor = PermitVisitor.new visitor.visit(result.value) visitor.permitted.uniq.map(&:to_s) end |
#file_path ⇒ Object
38 39 40 |
# File 'lib/rails-api-docs/inspectors/controller_inspector.rb', line 38 def file_path File.join(@root, "app/controllers", "#{@controller}_controller.rb") end |