Module: Uniword::ModelAttributeAccess

Included in:
Wordprocessingml::RunProperties
Defined in:
lib/uniword/model_attribute_access.rb

Overview

Model attribute access helpers for lutaml-model classes.

Provides read_attribute/write_attribute methods that call the public getters/setters generated by lutaml-model for declared attributes.

Validates that the attribute name exists in the model's schema before dispatching through the model's public method table — only attributes that are part of the model's declared public API can be accessed.

Instance Method Summary collapse

Instance Method Details

#read_attribute(name) ⇒ Object

Read a declared attribute's value by name.

Parameters:

  • name (Symbol)

    Declared attribute name

Returns:

  • (Object)

    The attribute value

Raises:

  • (ArgumentError)

    if the attribute is not declared on the model



17
18
19
20
# File 'lib/uniword/model_attribute_access.rb', line 17

def read_attribute(name)
  validate_declared_attribute!(name)
  method(name).call
end

#write_attribute(name, value) ⇒ Object

Write a declared attribute's value by name.

Parameters:

  • name (Symbol)

    Declared attribute name

  • value (Object)

    The value to assign

Raises:

  • (ArgumentError)

    if the attribute is not declared on the model



26
27
28
29
# File 'lib/uniword/model_attribute_access.rb', line 26

def write_attribute(name, value)
  validate_declared_attribute!(name)
  method(:"#{name}=").call(value)
end