Class: RailsOpenapiGen::Parsers::Jbuilder::Processors::CompositeProcessor
- Inherits:
-
BaseProcessor
- Object
- Parser::AST::Processor
- BaseProcessor
- RailsOpenapiGen::Parsers::Jbuilder::Processors::CompositeProcessor
- Defined in:
- lib/rails-openapi-gen/parsers/jbuilder/processors/composite_processor.rb
Constant Summary collapse
- CallDetectors =
Alias for shorter reference to call detectors
RailsOpenapiGen::Parsers::Jbuilder::CallDetectors
Constants inherited from BaseProcessor
Instance Method Summary collapse
-
#initialize(file_path, property_parser) ⇒ CompositeProcessor
constructor
Initializes composite processor with all sub-processors.
-
#on_block(node) ⇒ void
Processes block nodes by delegating to appropriate processors.
-
#on_send(node) ⇒ void
Processes method call nodes by delegating to appropriate processors.
Methods inherited from BaseProcessor
#handler_missing, #on_if, #partials, #properties
Constructor Details
#initialize(file_path, property_parser) ⇒ CompositeProcessor
Initializes composite processor with all sub-processors
17 18 19 20 21 22 23 24 25 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/processors/composite_processor.rb', line 17 def initialize(file_path, property_parser) super(file_path, property_parser) # Initialize sub-processors @array_processor = ArrayProcessor.new(file_path, property_parser) @object_processor = ObjectProcessor.new(file_path, property_parser) @property_processor = PropertyProcessor.new(file_path, property_parser) @partial_processor = PartialProcessor.new(file_path, property_parser) end |
Instance Method Details
#on_block(node) ⇒ void
This method returns an undefined value.
Processes block nodes by delegating to appropriate processors
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/processors/composite_processor.rb', line 55 def on_block(node) send_node, args_node, body = node.children receiver, method_name, = send_node.children if CallDetectors::CacheCallDetector.cache_call?(receiver, method_name) || CallDetectors::CacheCallDetector.cache_if_call?(receiver, method_name) # This is json.cache! or json.cache_if! block - just process the block contents process(body) if body elsif CallDetectors::JsonCallDetector.json_property?(receiver, method_name) && method_name != :array! # Check if this is an array iteration block (has block arguments) if args_node && args_node.type == :args && args_node.children.any? # This is an array iteration block like json.tags @tags do |tag| @array_processor.on_block(node) merge_processor_results(@array_processor) else # This is a nested object block like json.profile do @object_processor.on_block(node) merge_processor_results(@object_processor) end elsif CallDetectors::ArrayCallDetector.array_call?(receiver, method_name) # This is json.array! block @array_processor.on_block(node) merge_processor_results(@array_processor) else super end end |
#on_send(node) ⇒ void
This method returns an undefined value.
Processes method call nodes by delegating to appropriate processors
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/processors/composite_processor.rb', line 30 def on_send(node) receiver, method_name, = node.children # Skip Jbuilder helper methods - they are not JSON properties if CallDetectors::CacheCallDetector.cache_call?(receiver, method_name) || CallDetectors::CacheCallDetector.cache_if_call?(receiver, method_name) || CallDetectors::KeyFormatDetector.key_format?(receiver, method_name) || CallDetectors::NullHandlingDetector.null_handling?(receiver, method_name) || CallDetectors::ObjectManipulationDetector.object_manipulation?(receiver, method_name) super elsif CallDetectors::ArrayCallDetector.array_call?(receiver, method_name) @array_processor.on_send(node) merge_processor_results(@array_processor) elsif CallDetectors::PartialCallDetector.partial_call?(receiver, method_name) @partial_processor.on_send(node) merge_processor_results(@partial_processor) elsif CallDetectors::JsonCallDetector.json_property?(receiver, method_name) @property_processor.on_send(node) merge_processor_results(@property_processor) end end |