Class: GrapeOAS::Exporter::Registry
- Inherits:
-
Object
- Object
- GrapeOAS::Exporter::Registry
- Defined in:
- lib/grape_oas/exporter/registry.rb
Overview
Registry for managing schema exporters for different OpenAPI versions. Allows third-party gems to register custom exporters for new formats.
Instance Method Summary collapse
-
#clear ⇒ self
Clears all registered exporters.
-
#for(schema_type) ⇒ Class
Finds the exporter class for a given schema type.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(exporter_class, as:) ⇒ self
Registers an exporter class for one or more schema types.
-
#registered?(schema_type) ⇒ Boolean
Checks if an exporter is registered for the given schema type.
-
#schema_types ⇒ Array<Symbol>
Returns all registered schema types.
-
#size ⇒ Integer
Returns the number of registered exporters.
-
#unregister(*schema_types) ⇒ self
Unregisters an exporter for one or more schema types.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
15 16 17 |
# File 'lib/grape_oas/exporter/registry.rb', line 15 def initialize @exporters = {} end |
Instance Method Details
#clear ⇒ self
Clears all registered exporters.
76 77 78 79 |
# File 'lib/grape_oas/exporter/registry.rb', line 76 def clear @exporters.clear self end |
#for(schema_type) ⇒ Class
Finds the exporter class for a given schema type.
44 45 46 47 48 49 |
# File 'lib/grape_oas/exporter/registry.rb', line 44 def for(schema_type) exporter = @exporters[schema_type] raise ArgumentError, "Unsupported schema type: #{schema_type}" unless exporter exporter end |
#register(exporter_class, as:) ⇒ self
Registers an exporter class for one or more schema types.
24 25 26 27 28 |
# File 'lib/grape_oas/exporter/registry.rb', line 24 def register(exporter_class, as:) schema_types = Array(as) schema_types.each { |type| @exporters[type] = exporter_class } self end |
#registered?(schema_type) ⇒ Boolean
Checks if an exporter is registered for the given schema type.
55 56 57 |
# File 'lib/grape_oas/exporter/registry.rb', line 55 def registered?(schema_type) @exporters.key?(schema_type) end |
#schema_types ⇒ Array<Symbol>
Returns all registered schema types.
62 63 64 |
# File 'lib/grape_oas/exporter/registry.rb', line 62 def schema_types @exporters.keys end |
#size ⇒ Integer
Returns the number of registered exporters.
69 70 71 |
# File 'lib/grape_oas/exporter/registry.rb', line 69 def size @exporters.size end |
#unregister(*schema_types) ⇒ self
Unregisters an exporter for one or more schema types.
34 35 36 37 |
# File 'lib/grape_oas/exporter/registry.rb', line 34 def unregister(*schema_types) schema_types.flatten.each { |type| @exporters.delete(type) } self end |