Class: Openphar::Registry::TypeRegistry
- Inherits:
-
Object
- Object
- Openphar::Registry::TypeRegistry
- Defined in:
- lib/openphar/registry/type_registry.rb
Overview
Central registry for mapping JSON-LD @type to Ruby model classes.
This registry provides a single source of truth for type mappings, decoupling type resolution from specific exporters (like Neo4j).
Built-in Types
The registry comes pre-populated with all core and publisher-specific model types. Publishers can register additional types at runtime.
Class Method Summary collapse
-
.all_classes ⇒ Array<Class>
Returns all registered model classes.
-
.all_types ⇒ Array<String>
Returns all registered type names.
-
.clear ⇒ void
Clears all registered types (useful for testing).
-
.for(type) ⇒ Class?
Returns the model class for a given JSON-LD @type.
-
.register(type, model_class) ⇒ void
Registers a new type-to-class mapping.
-
.registered?(type) ⇒ Boolean
Checks if a type is registered.
-
.reset ⇒ void
Resets to default registrations.
-
.unregister(type) ⇒ void
Unregisters a type mapping.
Class Method Details
.all_classes ⇒ Array<Class>
Returns all registered model classes.
73 74 75 |
# File 'lib/openphar/registry/type_registry.rb', line 73 def all_classes registry.values.map { |v| v.is_a?(Proc) ? v.call : v } end |
.all_types ⇒ Array<String>
Returns all registered type names.
66 67 68 |
# File 'lib/openphar/registry/type_registry.rb', line 66 def all_types registry.keys end |
.clear ⇒ void
This method returns an undefined value.
Clears all registered types (useful for testing).
80 81 82 |
# File 'lib/openphar/registry/type_registry.rb', line 80 def clear @registry = nil end |
.for(type) ⇒ Class?
Returns the model class for a given JSON-LD @type.
31 32 33 34 35 36 |
# File 'lib/openphar/registry/type_registry.rb', line 31 def for(type) return nil if type.nil? || type.empty? entry = registry[type] entry.is_a?(Proc) ? entry.call : entry end |
.register(type, model_class) ⇒ void
This method returns an undefined value.
Registers a new type-to-class mapping.
43 44 45 |
# File 'lib/openphar/registry/type_registry.rb', line 43 def register(type, model_class) registry[type] = model_class end |
.registered?(type) ⇒ Boolean
Checks if a type is registered.
59 60 61 |
# File 'lib/openphar/registry/type_registry.rb', line 59 def registered?(type) registry.key?(type) end |
.reset ⇒ void
This method returns an undefined value.
Resets to default registrations.
87 88 89 |
# File 'lib/openphar/registry/type_registry.rb', line 87 def reset clear end |
.unregister(type) ⇒ void
This method returns an undefined value.
Unregisters a type mapping.
51 52 53 |
# File 'lib/openphar/registry/type_registry.rb', line 51 def unregister(type) registry.delete(type) end |