Base
Base class for member response wrappers.
Member wrappers structure responses for show, create, and update actions that return a single record. Extend this class to customize how individual resources are wrapped in your API responses.
Example: Custom member wrapper
ruby
class MyMemberWrapper < Wrapper::Member::Base
shape do
reference(root_key.singular.to_sym, to: data_type)
object?(:meta)
metadata_type_names.each { |type_name| merge(type_name) }
end
def wrap
{ root_key.singular.to_sym => data, meta: meta.presence, **metadata }.compact
end
endClass Methods
.shape
.shape(klass_or_callable = nil, &block)
Defines the response shape for contract generation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
klass_or_callable | Class<Shape>, Proc, nil | nil | A Shape subclass or callable. |
Returns
Class<Shape>, nil
Instance Methods
#data
#data
The data for this wrapper.
Returns
Hash
#meta
#meta
The meta for this wrapper.
Returns
Hash
#metadata
#metadata
The metadata for this wrapper.
Returns
Hash
#wrap
#wrap
Transforms the data into the final response format.
Returns
Hash