Class: Pubid::TypeResolver
- Inherits:
-
Object
- Object
- Pubid::TypeResolver
- Defined in:
- lib/pubid/type_resolver.rb
Overview
Resolves a polymorphic _type string (e.g. "pubid:iso:technical-report")
to the concrete Ruby class that owns it.
Each flavor's Identifier base owns a polymorphic_type_map for the types
defined in its own namespace. A nested polymorphic attribute (e.g. a GOST
Harmonized identifier's adopted ISO identifier) carries a _type from a
different flavor, so the owning flavor's map misses. This service routes
the lookup to the registered flavor whose name appears in the type's
second segment ("pubid:
Constant Summary collapse
- TYPE_PREFIX =
"pubid:"- SEGMENT_SEPARATOR =
":"
Class Method Summary collapse
-
.resolve(type) ⇒ Class<Pubid::Identifier>?
The concrete class, or nil if the type is blank, malformed, or unknown to its flavor.
Class Method Details
.resolve(type) ⇒ Class<Pubid::Identifier>?
Returns The concrete class, or nil if the type is blank, malformed, or unknown to its flavor.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pubid/type_resolver.rb', line 22 def resolve(type) return nil unless type.is_a?(String) flavor_name = flavor_segment(type) return nil unless flavor_name # Ensure the flavor module is loaded so its self-register call has # run; without this, Registry may know of flavors that haven't yet # populated their Identifier base's polymorphic_type_map. ::Pubid.eager_load_flavors! flavor = ::Pubid::Registry.get(flavor_name) return nil unless flavor identifier_base = flavor::Identifier identifier_base.polymorphic_type_map[type] rescue NameError # Flavor module is registered but its Identifier base cannot be # loaded (autoload failure). Treat as unresolvable. nil end |