Class: GrapeOAS::Introspectors::EntityIntrospectorSupport::CycleTracker
- Inherits:
-
Object
- Object
- GrapeOAS::Introspectors::EntityIntrospectorSupport::CycleTracker
- Defined in:
- lib/grape_oas/introspectors/entity_introspector_support/cycle_tracker.rb
Overview
Tracks and handles cyclic references during entity introspection.
Instance Method Summary collapse
-
#cyclic_reference? ⇒ Boolean
Checks if the current entity class is already in the processing stack.
-
#handle_cycle(schema) ⇒ ApiModel::Schema
Handles a detected cycle by marking the schema with a description.
-
#initialize(entity_class, stack) ⇒ CycleTracker
constructor
A new instance of CycleTracker.
-
#with_tracking { ... } ⇒ Object
Executes a block while tracking the current entity in the stack.
Constructor Details
#initialize(entity_class, stack) ⇒ CycleTracker
Returns a new instance of CycleTracker.
8 9 10 11 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/cycle_tracker.rb', line 8 def initialize(entity_class, stack) @entity_class = entity_class @stack = stack end |
Instance Method Details
#cyclic_reference? ⇒ Boolean
Checks if the current entity class is already in the processing stack.
16 17 18 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/cycle_tracker.rb', line 16 def cyclic_reference? @stack.include?(@entity_class) end |
#handle_cycle(schema) ⇒ ApiModel::Schema
Handles a detected cycle by marking the schema with a description.
24 25 26 27 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/cycle_tracker.rb', line 24 def handle_cycle(schema) schema.description ||= "Cycle detected while introspecting" schema end |
#with_tracking { ... } ⇒ Object
Executes a block while tracking the current entity in the stack.
33 34 35 36 37 38 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/cycle_tracker.rb', line 33 def with_tracking @stack << @entity_class yield ensure @stack.pop end |