Class: Lutaml::Hal::Resource
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Hal::Resource
- Defined in:
- lib/lutaml/hal/resource.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.link_definitions ⇒ Object
Returns the value of attribute link_definitions.
Instance Attribute Summary collapse
-
#_global_register_id ⇒ Object
Returns the value of attribute _global_register_id.
-
#embedded_data ⇒ Object
Returns the value of attribute embedded_data.
Class Method Summary collapse
- .create_link_class(realize_class_name) ⇒ Object
- .create_link_set_class ⇒ Object
- .from_embedded(json_data, register_name = nil) ⇒ Object
- .get_link_set_class ⇒ Object
- .hal_link(attr_key, key:, realize_class:, link_class: nil, link_set_class: nil, collection: false, type: :link) ⇒ Object
- .inherited(subclass) ⇒ Object
- .init_links_definition ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.link_definitions ⇒ Object
Returns the value of attribute link_definitions.
25 26 27 |
# File 'lib/lutaml/hal/resource.rb', line 25 def link_definitions @link_definitions end |
Instance Attribute Details
#_global_register_id ⇒ Object
Returns the value of attribute _global_register_id.
8 9 10 |
# File 'lib/lutaml/hal/resource.rb', line 8 def _global_register_id @_global_register_id end |
#embedded_data ⇒ Object
Returns the value of attribute embedded_data.
8 9 10 |
# File 'lib/lutaml/hal/resource.rb', line 8 def @embedded_data end |
Class Method Details
.create_link_class(realize_class_name) ⇒ Object
101 102 103 |
# File 'lib/lutaml/hal/resource.rb', line 101 def create_link_class(realize_class_name) LinkClassFactory.create_for(self, realize_class_name) end |
.create_link_set_class ⇒ Object
93 94 95 |
# File 'lib/lutaml/hal/resource.rb', line 93 def create_link_set_class LinkSetClassFactory.create_for(self) end |
.from_embedded(json_data, register_name = nil) ⇒ Object
18 19 20 21 22 |
# File 'lib/lutaml/hal/resource.rb', line 18 def self.(json_data, register_name = nil) instance = from_json(json_data.to_json) instance._global_register_id = register_name if register_name instance end |
.get_link_set_class ⇒ Object
89 90 91 |
# File 'lib/lutaml/hal/resource.rb', line 89 def get_link_set_class create_link_set_class end |
.hal_link(attr_key, key:, realize_class:, link_class: nil, link_set_class: nil, collection: false, type: :link) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/lutaml/hal/resource.rb', line 34 def hal_link(attr_key, key:, realize_class:, link_class: nil, link_set_class: nil, collection: false, type: :link) raise ArgumentError, 'realize_class parameter is required' if realize_class.nil? attribute_name = attr_key.to_sym Hal.debug_log "Defining HAL link for `#{attr_key}` with realize class `#{realize_class}`" realize_class_name = case realize_class when Class realize_class.name.split('::').last when String realize_class else raise ArgumentError, "realize_class must be a Class or String, got #{realize_class.class}" end link_set_klass = link_set_class || create_link_set_class raise 'Failed to create LinkSet class' if link_set_klass.nil? link_klass = link_class || create_link_class(realize_class_name) unless link_set_class link_set_klass.class_eval do if collection attribute attribute_name, link_klass, collection: true else attribute attribute_name, link_klass end key_value do map key, to: attribute_name end end end link_def = { attribute_name: attribute_name, key: attr_key, klass: link_klass, collection: collection, type: type } @link_definitions ||= {} @link_definitions[key] = link_def end |
.inherited(subclass) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/lutaml/hal/resource.rb', line 27 def inherited(subclass) super subclass.class_eval do init_links_definition end end |
.init_links_definition ⇒ Object
97 98 99 |
# File 'lib/lutaml/hal/resource.rb', line 97 def init_links_definition @link_definitions = {} end |
Instance Method Details
#get_embedded(key) ⇒ Object
14 15 16 |
# File 'lib/lutaml/hal/resource.rb', line 14 def (key) &.[](key.to_s) end |
#has_embedded?(key) ⇒ Boolean
10 11 12 |
# File 'lib/lutaml/hal/resource.rb', line 10 def (key) &.key?(key.to_s) end |