class Lutaml::Hal::Resource
def hal_link(attr_key,
is a collection of resources or a single resource
The "collection" is a boolean indicating if the link
The "realize_class" is the class to be realized
The "key" is the name of the attribute in the JSON
The developer defines a link to another resource
def hal_link(attr_key, key:, realize_class:, link_class: nil, link_set_class: nil, collection: false, type: :link) # Use the provided "key" as the attribute name attribute_name = attr_key.to_sym Hal.debug_log "Defining HAL link for `#{attr_key}` with realize class `#{realize_class}`" # Create a dynamic Link subclass name based on "realize_class", the # class to realize for a Link object, if `link_class:` is not provided. link_klass = link_class || create_link_class(realize_class) # Create a dynamic LinkSet class if `link_set_class:` is not provided. unless link_set_class link_set_klass = link_set_class || get_link_set_class link_set_klass.class_eval do # Declare the corresponding lutaml-model attribute attribute attribute_name, link_klass, collection: collection # Define the mapping for the attribute key_value do map key, to: attribute_name end end end # Create a new link definition for future reference link_def = { attribute_name: attribute_name, key: attr_key, klass: link_klass, collection: collection, type: type } @link_definitions ||= {} @link_definitions[key] = link_def end