Base
Base class for capability Operation phase.
Operation phase runs on each request. Use it to transform data at runtime.
Class Methods
.metadata_shape
.metadata_shape(klass = nil, &block)
Defines metadata shape for this operation.
Pass a block or a MetadataShape subclass. Blocks are evaluated via instance_exec, providing access to type DSL methods and capability options.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
klass | Class<MetadataShape>, nil | nil | The metadata shape class. |
Returns
Class<MetadataShape>, nil
Example: With block
metadata_shape do
reference(:pagination, to: :offset_pagination)
endExample: With class
metadata_shape PaginationShape.target
.target(value = nil)
The target for this operation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value | Symbol<:collection, :member>, nil | nil | The target type. |
Returns
Symbol, nil
Instance Methods
#apply
#apply
Applies this operation to the data.
Override this method to implement transformation logic. Return nil if no changes are made.
Returns
Result, nil
#data
#data
The data for this operation.
Returns
Object
#options
#options
The options for this operation.
Returns
#representation_class
#representation_class
The representation class for this operation.
Returns
Class<Representation::Base>
#result
#result(data: nil, includes: nil, metadata: nil, serialize_options: nil)
Creates a result object.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
data | Object, nil | nil | The transformed data. |
includes | Array, nil | nil | The associations to preload. |
metadata | Hash, nil | nil | The metadata to add to response. |
serialize_options | Hash, nil | nil | The options for serialization. |
Returns
Result
#translate
#translate(*segments, default: nil)
Translates a key using the adapter's i18n convention.
Lookup order:
apiwork.apis.<locale_key>.adapters.<adapter_name>.capabilities.<capability_name>.<segments>apiwork.adapters.<adapter_name>.capabilities.<capability_name>.<segments>- Provided default
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
segments | Array<Symbol, String> | The key path segments. | |
default | String, nil | nil | The fallback value if no translation found. |
Returns
String, nil
Example
translate(:issues, :invalid, :detail)
# Tries: apiwork.apis.billing.adapters.standard.capabilities.writing.issues.invalid.detail
# Falls back to: apiwork.adapters.standard.capabilities.writing.issues.invalid.detail