Class: RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::DetectorRegistry
- Inherits:
-
Object
- Object
- RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::DetectorRegistry
- Defined in:
- lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb
Overview
Registry for managing all call detectors
Class Method Summary collapse
-
.all_detectors ⇒ Array<Class>
Get all available detectors sorted by priority.
-
.by_category(category) ⇒ Array<Class>
Get detectors by category.
-
.categories ⇒ Array<Symbol>
Get all available categories.
-
.find_detector(receiver, method_name, args = []) ⇒ Class?
Find the appropriate detector for a method call.
-
.handles?(receiver, method_name, args = []) ⇒ Boolean
Check if a method call is handled by any detector.
-
.register(detector_class) ⇒ void
Add a custom detector to the registry.
-
.unregister(detector_class) ⇒ void
Remove a detector from the registry.
Class Method Details
.all_detectors ⇒ Array<Class>
Get all available detectors sorted by priority
18 19 20 21 22 23 24 25 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb', line 18 def all_detectors @all_detectors ||= [ ArrayCallDetector, PartialCallDetector, JsonCallDetector, CacheCallDetector ].sort_by { |detector| -detector.priority } end |
.by_category(category) ⇒ Array<Class>
Get detectors by category
56 57 58 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb', line 56 def by_category(category) all_detectors.select { |detector| detector.category == category } end |
.categories ⇒ Array<Symbol>
Get all available categories
62 63 64 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb', line 62 def categories all_detectors.map(&:category).uniq end |
.find_detector(receiver, method_name, args = []) ⇒ Class?
Find the appropriate detector for a method call
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb', line 32 def find_detector(receiver, method_name, args = []) if ENV['RAILS_OPENAPI_DEBUG'] puts "🔍 DEBUG: DetectorRegistry.find_detector called with method: #{method_name}" puts "🔍 DEBUG: Available detectors: #{all_detectors.map(&:name)}" end result = all_detectors.find do |detector| handles = detector.handles?(receiver, method_name, args) if ENV['RAILS_OPENAPI_DEBUG'] puts "🔍 DEBUG: #{detector.name}.handles?(#{receiver}, #{method_name}, #{args}) = #{handles}" end handles end if ENV['RAILS_OPENAPI_DEBUG'] puts "🔍 DEBUG: Found detector: #{result ? result.name : 'nil'}" end result end |
.handles?(receiver, method_name, args = []) ⇒ Boolean
Check if a method call is handled by any detector
90 91 92 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb', line 90 def handles?(receiver, method_name, args = []) !find_detector(receiver, method_name, args).nil? end |
.register(detector_class) ⇒ void
This method returns an undefined value.
Add a custom detector to the registry
69 70 71 72 73 74 75 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb', line 69 def register(detector_class) return unless detector_class < BaseDetector @all_detectors = nil # Reset cache all_detectors << detector_class unless all_detectors.include?(detector_class) @all_detectors = all_detectors.sort_by { |detector| -detector.priority } end |
.unregister(detector_class) ⇒ void
This method returns an undefined value.
Remove a detector from the registry
80 81 82 83 |
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors.rb', line 80 def unregister(detector_class) @all_detectors = nil # Reset cache all_detectors.delete(detector_class) end |