Class: RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::JsonCallDetector
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::JsonCallDetector
- Defined in:
- lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb
Overview
Detects JSON property calls (json.property_name) Handles the most common Jbuilder pattern for setting properties
Constant Summary collapse
- SPECIAL_METHODS =
JSON methods that should not be treated as properties
%w[array! partial! cache! cache_if! key_format! null! ignore_nil!].freeze
Class Method Summary collapse
-
.array_call?(receiver, method_name) ⇒ Boolean
Checks if this is an array-related call (json.array!).
-
.category ⇒ Symbol
Detector category.
-
.description ⇒ String
Description.
-
.handles?(receiver, method_name, _args = []) ⇒ Boolean
Check if this detector handles the method call.
-
.json_property?(receiver, method_name) ⇒ Boolean
Checks if this is a json property call (json.property_name).
-
.partial_call?(receiver, method_name) ⇒ Boolean
Checks if this is a partial call (json.partial!).
-
.priority ⇒ Integer
Higher priority since this is the most common case.
-
.property_with_block?(receiver, method_name, has_block) ⇒ Boolean
Check if method call represents a property with block (object).
-
.simple_property?(receiver, method_name, args) ⇒ Boolean
Check if method call represents a simple property assignment.
Class Method Details
.array_call?(receiver, method_name) ⇒ Boolean
Checks if this is an array-related call (json.array!)
57 58 59 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 57 def array_call?(receiver, method_name) method_name == :array! && json_receiver?(receiver) end |
.category ⇒ Symbol
Returns Detector category.
29 30 31 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 29 def category :property end |
.description ⇒ String
Returns Description.
34 35 36 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 34 def description "JSON property calls (json.property_name)" end |
.handles?(receiver, method_name, _args = []) ⇒ Boolean
Check if this detector handles the method call
18 19 20 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 18 def handles?(receiver, method_name, _args = []) json_property?(receiver, method_name) end |
.json_property?(receiver, method_name) ⇒ Boolean
Checks if this is a json property call (json.property_name)
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 42 def json_property?(receiver, method_name) return false if method_name.nil? return false if SPECIAL_METHODS.include?(method_name.to_s) # Don't handle bare "json" calls - these are receivers, not properties return false if receiver.nil? && method_name == :json # Must be called on json (implicit or explicit) json_receiver?(receiver) end |
.partial_call?(receiver, method_name) ⇒ Boolean
Checks if this is a partial call (json.partial!)
65 66 67 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 65 def partial_call?(receiver, method_name) method_name == :partial! && json_receiver?(receiver) end |
.priority ⇒ Integer
Higher priority since this is the most common case
24 25 26 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 24 def priority 10 end |
.property_with_block?(receiver, method_name, has_block) ⇒ Boolean
Check if method call represents a property with block (object)
86 87 88 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 86 def property_with_block?(receiver, method_name, has_block) json_property?(receiver, method_name) && has_block end |
.simple_property?(receiver, method_name, args) ⇒ Boolean
Check if method call represents a simple property assignment
74 75 76 77 78 79 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/json_call_detector.rb', line 74 def simple_property?(receiver, method_name, args) return false unless json_property?(receiver, method_name) # Simple property has exactly one argument and no block args.length == 1 end |