Class: RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::ArrayCallDetector
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::ArrayCallDetector
- Defined in:
- lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb
Overview
Detects array calls (json.array!) Handles array generation in Jbuilder templates
Class Method Summary collapse
-
.array_call?(receiver, method_name) ⇒ Boolean
Check if this is an array call.
-
.category ⇒ Symbol
Detector category.
-
.description ⇒ String
Description.
-
.extract_collection(args) ⇒ Parser::AST::Node?
Extract collection from array arguments.
-
.extract_options(args) ⇒ Parser::AST::Node?
Extract options hash from array arguments.
-
.handles?(receiver, method_name, _args = []) ⇒ Boolean
Check if this detector handles the method call.
-
.has_collection?(args) ⇒ Boolean
Check if array call has collection argument.
-
.has_options?(args) ⇒ Boolean
Check if array call has options hash.
-
.has_partial_key?(hash_node) ⇒ Boolean
Check if arguments contain partial key in hash.
-
.priority ⇒ Integer
High priority for array calls.
-
.uses_partial?(args) ⇒ Boolean
Check if array call uses partial rendering.
Class Method Details
.array_call?(receiver, method_name) ⇒ Boolean
Check if this is an array call
48 49 50 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 48 def array_call?(receiver, method_name) method_name == :array! && json_receiver?(receiver) end |
.category ⇒ Symbol
Returns Detector category.
35 36 37 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 35 def category :array end |
.description ⇒ String
Returns Description.
40 41 42 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 40 def description "Array calls (json.array!)" end |
.extract_collection(args) ⇒ Parser::AST::Node?
Extract collection from array arguments
83 84 85 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 83 def extract_collection(args) args.find { |arg| arg.type != :hash } end |
.extract_options(args) ⇒ Parser::AST::Node?
Extract options hash from array arguments
90 91 92 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 90 def (args) args.find { |arg| arg.type == :hash } end |
.handles?(receiver, method_name, _args = []) ⇒ Boolean
Check if this detector handles the method call
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 15 def handles?(receiver, method_name, _args = []) result = array_call?(receiver, method_name) if ENV['RAILS_OPENAPI_DEBUG'] puts "🔍 DEBUG: ArrayCallDetector.handles? for #{method_name}" puts " receiver: #{receiver.inspect}" puts " method_name: #{method_name.inspect}" puts " method_name == :array!: #{method_name == :array!}" puts " json_receiver?: #{json_receiver?(receiver)}" puts " result: #{result}" end result end |
.has_collection?(args) ⇒ Boolean
Check if array call has collection argument
69 70 71 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 69 def has_collection?(args) args.any? && !args.first.type == :hash end |
.has_options?(args) ⇒ Boolean
Check if array call has options hash
76 77 78 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 76 def (args) args.any? { |arg| arg.type == :hash } end |
.has_partial_key?(hash_node) ⇒ Boolean
Check if arguments contain partial key in hash
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 55 def has_partial_key?(hash_node) return false unless hash_node.type == :hash hash_node.children.any? do |pair| next false unless pair.type == :pair key, _value = pair.children key.type == :sym && key.children.first == :partial end end |
.priority ⇒ Integer
High priority for array calls
30 31 32 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 30 def priority 20 end |
.uses_partial?(args) ⇒ Boolean
Check if array call uses partial rendering
97 98 99 100 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/array_call_detector.rb', line 97 def uses_partial?(args) = (args) && has_partial_key?() end |