Class: RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::PartialCallDetector
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::PartialCallDetector
- Defined in:
- lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb
Overview
Detects partial calls (json.partial!) Handles partial template rendering in Jbuilder
Class Method Summary collapse
-
.category ⇒ Symbol
Detector category.
-
.description ⇒ String
Description.
-
.extract_locals(args) ⇒ Hash
Extract local variables from arguments.
-
.extract_partial_path(args) ⇒ String?
Extract partial path from arguments.
-
.handles?(receiver, method_name, _args = []) ⇒ Boolean
Check if this detector handles the method call.
-
.has_collection?(args) ⇒ Boolean
Check if partial is called with collection.
-
.has_locals?(args) ⇒ Boolean
Check if partial has locals.
-
.literal_path?(args) ⇒ Boolean
Check if partial path is a string literal.
-
.partial_call?(receiver, method_name) ⇒ Boolean
Check if this is a partial call.
-
.priority ⇒ Integer
High priority for partial calls.
Class Method Details
.category ⇒ Symbol
Returns Detector category.
26 27 28 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 26 def category :partial end |
.description ⇒ String
Returns Description.
31 32 33 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 31 def description "Partial calls (json.partial!)" end |
.extract_locals(args) ⇒ Hash
Extract local variables from arguments
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 71 def extract_locals(args) locals = {} args.each do |arg| next unless arg.type == :hash arg.children.each do |pair| next unless pair.type == :pair key_node, value_node = pair.children next unless key_node.type == :sym key = key_node.children.first next if key == :partial # Skip partial path # For now, just store the key, value extraction would need evaluation locals[key] = value_node end end locals end |
.extract_partial_path(args) ⇒ String?
Extract partial path from arguments
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 46 def extract_partial_path(args) return nil if args.empty? first_arg = args.first return extract_string_value(first_arg) if literal_node?(first_arg) # Check if it's in a hash under :partial key if first_arg.type == :hash partial_pair = first_arg.children.find do |pair| key_node = pair.children.first key_node.type == :sym && key_node.children.first == :partial end if partial_pair value_node = partial_pair.children.last return extract_string_value(value_node) end end nil end |
.handles?(receiver, method_name, _args = []) ⇒ Boolean
Check if this detector handles the method call
15 16 17 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 15 def handles?(receiver, method_name, _args = []) partial_call?(receiver, method_name) end |
.has_collection?(args) ⇒ Boolean
Check if partial is called with collection
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 113 def has_collection?(args) args.any? do |arg| next false unless arg.type == :hash arg.children.any? do |pair| key_node = pair.children.first key_node.type == :sym && key_node.children.first == :collection end end end |
.has_locals?(args) ⇒ Boolean
Check if partial has locals
97 98 99 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 97 def has_locals?(args) !extract_locals(args).empty? end |
.literal_path?(args) ⇒ Boolean
Check if partial path is a string literal
104 105 106 107 108 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 104 def literal_path?(args) return false if args.empty? literal_node?(args.first) end |
.partial_call?(receiver, method_name) ⇒ Boolean
Check if this is a partial call
39 40 41 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 39 def partial_call?(receiver, method_name) method_name == :partial! && json_receiver?(receiver) end |
.priority ⇒ Integer
High priority for partial calls
21 22 23 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/partial_call_detector.rb', line 21 def priority 20 end |