Class: Lutaml::Hal::Link
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Hal::Link
- Defined in:
- lib/lutaml/hal/link.rb
Overview
HAL Link representation with realization capability
Instance Attribute Summary collapse
-
#_global_register_id ⇒ Object
This is the model register that has fetched the origin of this link, and will be used to resolve unless overriden in resource#realize().
-
#parent_resource ⇒ Object
Store reference to parent resource for automatic embedded content detection.
Instance Method Summary collapse
-
#realize(register: nil, parent_resource: nil, force_refresh: false) ⇒ Object
Fetch the actual resource this link points to.
Instance Attribute Details
#_global_register_id ⇒ Object
This is the model register that has fetched the origin of this link, and will be used to resolve unless overriden in resource#realize()
12 13 14 |
# File 'lib/lutaml/hal/link.rb', line 12 def _global_register_id @_global_register_id end |
#parent_resource ⇒ Object
Store reference to parent resource for automatic embedded content detection
15 16 17 |
# File 'lib/lutaml/hal/link.rb', line 15 def parent_resource @parent_resource end |
Instance Method Details
#realize(register: nil, parent_resource: nil, force_refresh: false) ⇒ Object
Fetch the actual resource this link points to. This method will use the global register according to the source of the Link object. If the Link does not have a register, a register needs to be provided explicitly via the ‘register:` parameter.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lutaml/hal/link.rb', line 30 def realize(register: nil, parent_resource: nil, force_refresh: false) # Use provided parent_resource or fall back to stored parent_resource effective_parent = parent_resource || @parent_resource register = find_register(register) raise "No register provided for link resolution (class: #{self.class}, href: #{href})" if register.nil? # Priority 1: Check embedded content first (unless force_refresh) if !force_refresh && effective_parent && ( = (effective_parent, register)) # Cache embedded content too, so later lookups by href are served locally register.cache_manager&.set(href, nil, ) return end # Force refresh bypasses any cached entry for this href register.cache_manager&.invalidate(href) if force_refresh Hal.debug_log "Resolving link href: #{href} using register" register.resolve_and_cast(self, href) end |